This repository was archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
67 lines (53 loc) · 2.05 KB
/
bot.py
File metadata and controls
67 lines (53 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Import what's needed by the bot
import discord
from discord.ext import commands
import asyncio
import json
import datetime
import logging
import archcommands
# Set up logging
logging.basicConfig(level=logging.INFO)
# Set bot description
description = '''ArchBot is a Discord bot written in Python for searching the ArchWiki, Arch Linux package repositories, and AUR'''
# Open configuration file
with open('./config.json', 'r') as configjson:
config = json.load(configjson)
# Set prefix
prefix = config["prefix_settings"]["prefix"]
if config["prefix_settings"]["use_space"] == True:
prefix = prefix + ' '
# Create bot
bot = commands.Bot(command_prefix=prefix, description=description)
# Create a variable for the time the bot is launched
gametimestarted = datetime.datetime.now()
@bot.event
async def on_ready():
print('Logged in as ')
print(bot.user.name)
print(bot.user.id)
print('Bot prefix is set to ' + prefix + '\n')
await bot.change_presence(game=discord.Game(name='with systemd'))
@bot.command()
async def uptime():
"""Check bot uptime."""
global gametimestarted
await bot.say(timedelta_str(datetime.datetime.now() - gametimestarted))
@bot.command()
async def source():
"""Get the bot's source code"""
await bot.say("https://github.com/kingofinfo/ArchBot")
def timedelta_str(dt):
days = dt.days
hours, r = divmod(dt.seconds, 3600)
minutes, sec = divmod(r, 60)
if minutes == 1 and sec == 1:
return '{0} days, {1} hours, {2} minute and {3} second.'.format(days,hours,minutes,sec)
elif minutes > 1 and sec == 1:
return '{0} days, {1} hours, {2} minutes and {3} second.'.format(days,hours,minutes,sec)
elif minutes == 1 and sec > 1:
return '{0} days, {1} hours, {2} minute and {3} seconds.'.format(days,hours,minutes,sec)
else:
return '{0} days, {1} hours, {2} minutes and {3} seconds.'.format(days,hours,minutes,sec)
bot.add_cog(archcommands.General(bot,config))
bot.run(config['token'])