This repository was archived by the owner on May 10, 2022. 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
134 lines (98 loc) · 3.54 KB
/
bot.py
File metadata and controls
134 lines (98 loc) · 3.54 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# ive already did some coding
import discord
from discord.ext import commands
import yaml
import logging
import sys
import traceback
import os
import asyncio
import datetime
discord.VoiceClient.warn_nacl = False # don't need this warning
formatter = logging.Formatter(
'%(asctime)s [%(levelname)s] %(name)s: %(message)s', '%Y-%m-%d %H:%M:%S')
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger = logging.getLogger('discord')
# logger.setLevel(logging.INFO)
logger.addHandler(handler)
log = logging.getLogger('bot')
log.setLevel(logging.INFO)
# create file handler which logs even debug messages
# fh = logging.FileHandler('log.log')
# fh.setLevel(logging.DEBUG)
# log.addHandler(fh)
logging.basicConfig(
handlers=[logging.FileHandler('./logs/logfile.log', 'w', 'utf-8')],
format='%(asctime)s [%(levelname)s] %(name)s: %(message)s',
datefmt='%m-%d %H:%M',
level=logging.INFO # CRITICAL ERROR WARNING INFO DEBUG NOTSET
)
log.addHandler(handler)
initial_extensions = [
'cogs.events',
'cogs.game',
'cogs.admin',
'cogs.misc',
'cogs.debug',
]
def get_prefix(bot, message):
prefixes = [bot.config['prefix']]
return commands.when_mentioned_or(*prefixes)(bot, message)
# send function/method for easy sending of embed messages with small amounts of text
description = '''IDK what to put here'''
class Bot(commands.Bot):
def __init__(self):
intents = discord.Intents(messages=True, guilds=True, reactions=True)
super().__init__(
command_prefix=get_prefix,
description=description,
case_insensitive=False,
activity=discord.Game('Starting up...'),
help_command=commands.DefaultHelpCommand(),
# intents=intents,
)
self.log = log
log.info('Starting bot...')
log.info('Loading config file...')
self.config = self.load_config('config.yml')
log.info('Loading extensions...')
for extension in initial_extensions:
self.load_extension(extension)
log.info('Setting initial status before logging in...')
self.init_ok = None
self.restart_signal = None
self.uptime = datetime.datetime.now()
self.messages_in = self.messages_out = 0
self.region = 'Melbourne, AU'
try:
self.load_extension('jishaku')
except Exception:
log.info('jishaku is not installed, continuing...')
async def is_owner(self, user: discord.User):
owners = [442903946139271179, 316385640323481601,
468296341093613569, 325594915218128900]
for userid in owners:
if user.id == userid:
return True
# Else fall back to the original
return await super().is_owner(user)
def load_config(self, filename):
with open(filename, 'r') as f:
return yaml.safe_load(f)
async def set_status(self, status, text, *, force=False):
game = discord.Game(text)
# We only want to send a request if the status is different
# or if the status is not set.
# The below returns if either of those requirements are not met.
now = datetime.datetime.utcnow()
await self.change_presence(status=status, activity=game)
self.status = status
self.activity = game
log.info(f"Set status to {status}: {text}")
def run(self):
log.info('Logging into Discord...')
super().run(self.config['bot-token'])
if __name__ == '__main__':
bot = Bot()
bot.run()