-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
71 lines (54 loc) · 2.27 KB
/
main.py
File metadata and controls
71 lines (54 loc) · 2.27 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
import os, discord, logging
import countrybot.utils.io as io
from countrybot.configparser import LOG_FILE
from dotenv import load_dotenv
bot = discord.Bot()
initial_extensions = ['countrybot.cogs.date', 'countrybot.cogs.errorhandler', 'countrybot.cogs.country', 'countrybot.cogs.utility']
intents = discord.Intents.default()
load_dotenv()
logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename=LOG_FILE, encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
logger.addHandler(handler)
if __name__ == '__main__':
for extension in initial_extensions:
try:
bot.load_extension(extension)
except Exception as e:
print(e)
@bot.event
async def on_ready():
print(f'{bot.user} ~ Good morning, chat!')
activity = discord.Activity(
name=f"over your countries",
type=discord.ActivityType.watching,
)
await bot.change_presence(status=discord.Status.online, activity=activity)
bot_guilds = set([guild.id for guild in bot.guilds])
registered_guilds = set(await io.get_guilds())
guilds_joined = list(bot_guilds.difference(registered_guilds))
guilds_left = list(registered_guilds.difference(bot_guilds))
if len(guilds_joined) != 0:
print('Guilds joined since last episode...')
for guild in guilds_joined:
await io.register(guild)
guild = await bot.fetch_guild(guild)
print(f'- {bot.user} ~ Joined {guild.name} (id: {guild.id})')
if len(guilds_left) != 0:
print('Guilds left since last episode...')
for guild in guilds_left:
await io.unregister(guild)
print(f'- {bot.user} ~ Left guild (id: {guild}) :(')
@bot.event
async def on_application_command(ctx: discord.ApplicationContext):
print(f"{ctx.user} ~ used /{ctx.command} in {ctx.guild.name} (id: {ctx.guild.id})")
@bot.event
async def on_guild_join(guild: discord.Guild):
print(f'{bot.user} ~ Joined {guild.name} (id: {guild.id})')
await io.register(guild.id)
@bot.event
async def on_guild_remove(guild: discord.Guild):
print(f'{bot.user} ~ Left {guild.name} (id: {guild.id}) :(')
await io.unregister(guild.id)
bot.run(os.getenv('TOKEN'))