This repository has been archived by the owner on Sep 14, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbot.py
90 lines (76 loc) · 3.65 KB
/
bot.py
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
import discord
import logging
import pprint
from databases import Database
from discord.ext import commands
from logging.config import fileConfig
from typing import List
from utils.server import WebServer
from utils.csgo_server import CSGOServer
__version__ = '1.7.1'
__dev__ = 745000319942918303
class Discord_10man(commands.Bot):
def __init__(self, config: dict, startup_extensions: List[str]):
super().__init__(command_prefix=commands.when_mentioned_or('.'), case_insensitive=True, description='A bot to run CSGO PUGS.',
help_command=commands.DefaultHelpCommand(verify_checks=False),
intents=discord.Intents(
guilds=True, members=True, bans=True, emojis=True, integrations=True, invites=True,
voice_states=True, presences=False, messages=True, guild_messages=True, dm_messages=True,
reactions=True, guild_reactions=True, dm_reactions=True, typing=True, guild_typing=True,
dm_typing=True
))
fileConfig('logging.conf')
self.logger = logging.getLogger(f'10man.{__name__}')
self.logger.debug(f'Version = {__version__}')
self.logger.debug(f'config.json = \n {pprint.pformat(config)}')
self.token: str = config['discord_token']
self.bot_IP: str = config['bot_IP']
if 'bot_port' in config:
self.bot_port: int = config['bot_port']
else:
self.bot_port: int = 3000
self.steam_web_api_key = config['steam_web_API_key']
self.servers: List[CSGOServer] = []
# Will need to change for when there is multiple server queue
self.users_not_ready: List[discord.Member] = []
for i, server in enumerate(config['servers']):
self.servers.append(
CSGOServer(i, server['server_address'], server['server_port'], server['server_password'],
server['RCON_password']))
self.web_server = WebServer(bot=self)
self.dev: bool = False
self.version: str = __version__
self.queue_ctx: commands.Context = None
self.queue_voice_channel: discord.VoiceChannel = None
self.match_size = 10
self.spectators: List[discord.Member] = []
self.connect_dm = False
self.queue_captains: List[discord.Member] = []
for extension in startup_extensions:
self.load_extension(f'cogs.{extension}')
async def on_ready(self):
db = Database('sqlite:///main.sqlite')
await db.connect()
await db.execute('''
CREATE TABLE IF NOT EXISTS users(
discord_id TEXT UNIQUE,
steam_id TEXT
)''')
# TODO: Custom state for waiting for pug or if a pug is already playing
await self.change_presence(status=discord.Status.online,
activity=discord.Activity(type=discord.ActivityType.competing,
name='CSGO Pugs'))
self.dev = self.user.id == __dev__
self.logger.debug(f'Dev = {self.dev}')
await self.web_server.http_start()
self.logger.info(f'{self.user} connected.')
async def load(self, extension: str):
self.load_extension(f'cogs.{extension}')
async def unload(self, extension: str):
self.unload_extension(f'cogs.{extension}')
async def close(self):
self.logger.warning('Stopping Bot')
await self.web_server.http_stop()
await super().close()
def run(self):
super().run(self.token, reconnect=True)