This repository was archived by the owner on Oct 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbot.py
More file actions
49 lines (36 loc) · 1.41 KB
/
bot.py
File metadata and controls
49 lines (36 loc) · 1.41 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
import re
from datetime import timedelta
import discord
from discord.ext import commands
import requests
import asyncio
import logging
class ClusterBot(commands.AutoShardedBot):
def __init__(self, **kwargs):
self.pipe = kwargs.pop('pipe')
self.cluster_name = kwargs.pop('cluster_name')
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
super().__init__(**kwargs, loop=loop)
self.websocket = None
self._last_result = None
self.ws_task = None
self.responses = asyncio.Queue()
log = logging.getLogger(f"Cluster#{self.cluster_name}")
log.setLevel(logging.DEBUG)
log.handlers = [logging.FileHandler(f'cluster-{self.cluster_name}.log', encoding='utf-8', mode='a')]
log.info(f'[Cluster#{self.cluster_name}] {kwargs["shard_ids"]}, {kwargs["shard_count"]}')
self.log = log
self.run(kwargs['token'])
#self.loop.create_task(self.ensure_ipc())
async def on_ready(self, **kwargs):
print("[Client] All Shards Loaded!")
self.pipe.send(1)
self.pipe.close()
#keep_alive()
async def close(self, *args, **kwargs):
self.log.info("shutting down")
await self.websocket.close()
await super().close()
async def on_shard_ready(self, shard_id):
self.log.info(f'[Cluster#{self.cluster_name}] Shard {shard_id} ready')