Titan/discordbot/titanembeds/bot.py

78 lines
2.4 KiB
Python
Raw Permalink Normal View History

2017-05-04 05:22:27 +02:00
from config import config
2017-09-16 19:16:34 +02:00
from collections import deque
2018-12-30 21:55:24 +01:00
# from raven import Client as RavenClient
# import raven
2017-05-04 05:22:27 +02:00
import discord
import aiohttp
import asyncio
import sys
2017-05-15 00:09:38 +02:00
import logging
import json
2018-12-30 21:55:24 +01:00
# try:
# raven_client = RavenClient(config["sentry-dsn"])
# except raven.exceptions.InvalidDsn:
# pass
2021-03-13 00:21:03 +01:00
import traceback
2017-05-04 05:22:27 +02:00
2021-03-12 22:34:45 +01:00
intents = discord.Intents.default()
2021-03-13 00:39:26 +01:00
intents.members = True
2021-03-12 22:34:45 +01:00
class Titan(discord.AutoShardedClient):
def __init__(self, shard_ids=None, shard_count=None):
super().__init__(
shard_ids=shard_ids,
shard_count=shard_count,
max_messages=10000,
2021-03-12 22:34:45 +01:00
intents=intents,
activity=discord.Game(name="Embed your Discord server! Visit https://TitanEmbeds.com/")
)
self.setup_logger(shard_ids)
self.aiosession = aiohttp.ClientSession(loop=self.loop)
self.http.user_agent += ' TitanEmbeds-Bot'
2017-05-04 05:22:27 +02:00
def setup_logger(self, shard_ids=None):
shard_ids = '-'.join(str(x) for x in shard_ids) if shard_ids is not None else ''
logging.basicConfig(
filename='titanbot{}.log'.format(shard_ids),
level=logging.INFO,
format='%(asctime)s %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p'
)
logging.getLogger('TitanBot')
def _cleanup(self):
try:
self.loop.run_until_complete(self.logout())
except: # Can be ignored
pass
pending = asyncio.Task.all_tasks()
gathered = asyncio.gather(*pending)
try:
gathered.cancel()
self.loop.run_until_complete(gathered)
gathered.exception()
except: # Can be ignored
2020-02-17 23:40:53 +01:00
pass
async def start(self):
await super().start(config["bot-token"])
2020-02-17 23:47:32 +01:00
async def on_shard_ready(self, shard_id):
logging.info('Titan [DiscordBot]')
logging.info('Logged in as the following user:')
logging.info(self.user.name)
logging.info(self.user.id)
logging.info('------')
logging.info("Shard count: " + str(self.shard_count))
logging.info("Shard id: "+ str(shard_id))
logging.info("------")
2021-03-13 00:21:03 +01:00
async def on_socket_raw_send(self, data):
data = str(data)
try:
data = json.loads(data)
except:
return
logging.info('DEBUG LOG {}'.format(data.get("op", -1)))
logging.info('{}'.format(str(list(traceback.format_stack()))))