-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
102 lines (89 loc) · 3.43 KB
/
main.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
91
92
93
94
95
96
97
98
99
100
101
102
import discord
from discord.ext import commands
import asyncio
import os
from functions import *
# Checks the prefix for each guild
def prefixes_for(guild):
conn = Connection(guild.id)
return conn.query("SELECT flag FROM settings WHERE parameter='prefix'").fetchone()
# Bot Prefix
def get_prefix(bot, message):
if message.author.id == 160941453671923722:
prefixes = ["~"]
return commands.when_mentioned_or(*prefixes)(bot, message)
prefixes = prefixes_for(message.guild)
return commands.when_mentioned_or(*prefixes)(bot, message)
# Bot description
description = "MultiWorldBot - For organizing OoT Mutliworlds"
# Bot cogs
cogs = [
"cogs.owner",
"cogs.admin",
"cogs.planner",
"cogs.help",
"cogs.misc",
]
# Global check
def global_check(ctx):
return ctx.message.author.bot == False
# Intents
intents = discord.Intents.default()
intents.members = True
intents.presences = True
# Create the bot
bot = commands.Bot(
command_prefix=get_prefix,
owner_id=160941453671923722,
description=description,
# activity=discord.Game("Preparing the Multiworld")
activity=discord.Game("Use ~help for commands"),
guild_subscriptions=True,
intents=intents
)
# Start the show
if __name__ == '__main__':
bot.add_check(global_check)
bot.remove_command('help')
for cog in cogs:
try:
bot.load_extension(cog)
except Exception as e:
print("Failed to load cog: {}".format(e))
# When everything is ready
@bot.event
async def on_ready():
print("The bot is ready")
# conn = Connection("Admin")
#
# for guild in bot.guilds:
# conn.queryWithValues("INSERT INTO guilds VALUES(?, ?, ?, ?, ?, ?)", (guild.id, guild.name, guild.owner_id, guild.owner.name, guild.large, guild.member_count))
# Creates databases for a guild upon joining it
@bot.event
async def on_guild_join(guild):
try:
os.remove("databases/{}.db".format(guild.id))
except:
pass
conn = Connection(guild.id)
conn.query("CREATE TABLE settings(parameter, flag)")
conn.query("INSERT INTO settings VALUES('prefix', '~')")
conn.query("CREATE TABLE worlds(gameId INTEGER PRIMARY KEY AUTOINCREMENT, gameOwner int, maxPlayers int, open bool, finished bool, startTime timestamp, stopTime timestamp, connectionType text, connectionDetails text, seedSettings text, roleId int, voiceChannelId int, textChannelId int)")
conn.query("INSERT INTO worlds (gameId) VALUES (999)")
conn.query("CREATE TABLE players(gameId int, userId int, playerNum int, isCreator bool, isFinished bool, finishTime timestamp DEFAULT NULL)")
try:
category = await guild.create_category_channel("Multiworlds")
conn.queryWithValues("INSERT INTO settings VALUES('categoryId', ?)", (category.id, ))
except:
conn.query("INSERT INTO settings VALUES('categoryId', NULL)")
try:
owner = bot.get_user(160941453671923722)
msg = "I've joined a new guild:\n```\n"
msg += "Name: {}\nID: {}\nOwner ID: {}\nOwner Name: {}\nNumber of Members: {}\n```".format(guild.name, guild.id, guild.owner_id, guild.owner.name, guild.member_count)
await owner.send(msg)
except Exception as e:
print(e)
conn = Connection("Admin")
conn.queryWithValues("INSERT INTO guilds VALUES(?, ?, ?, ?, ?, ?)", (guild.id, guild.name, guild.owner_id, guild.owner.name, guild.large, guild.member_count))
# Run the bot
bot.run('', bot=True, reconnect=True)