This repository has been archived by the owner on Sep 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·104 lines (82 loc) · 2.84 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
103
104
import traceback
import discord
import datetime
from discord.ext import commands
from utils import help
from utils.miniutils import classes, data, minidiscord
with open('token.txt') as f:
token = [line.strip() for line in f]
production = False
try:
open("devmode").close()
except FileNotFoundError:
production = True
main_prefix = "$" if production else "£"
cogs = [
"utils.constants",
"cogs.info",
"cogs.disclaimer",
"jishaku",
"guildmanager.cog",
"cogs.cah",
"cogs.botlist",
"cogs.ping"
]
prefixes = data.Json("prefixes")
def get_command_prefix(_bot, message):
if message.guild:
custom_prefixes = prefixes.read_key(message.guild.id)
if custom_prefixes:
return commands.when_mentioned_or(*custom_prefixes)(_bot, message)
return commands.when_mentioned_or(main_prefix)(_bot, message)
def get_main_custom_prefix(message):
if message.guild:
custom_prefixes = prefixes.read_key(message.guild.id)
if custom_prefixes:
return custom_prefixes[0]
return bot.main_prefix
bot = minidiscord.AutoShardedBot(
command_prefix=get_command_prefix,
case_insensitive=True,
help_command=help.HelpCommand(),
owner_ids=[317731855317336067, 438733159748599813, 261900651230003201, 421698654189912064],
exceptions_channel=765245653919596596,
activity=discord.Activity(
name="Discord go by.",
type=discord.ActivityType.watching
), # We create a discord activity to start up with
status=discord.Status.idle
)
bot.prefixes = prefixes
bot.get_main_custom_prefix = get_main_custom_prefix
bot.playing = 0
bot.AIDataStore = data.Json("AIStore" + str(datetime.datetime.utcnow().timestamp()))
bot.AIAnswerStore = data.Json("answers")
bot.AIQuestionStore = data.Json("questions")
bot.admins = [] + bot.owner_ids
bot.skips = []
bot.main_prefix = main_prefix
bot.runningPing = False
@bot.event
async def on_ready():
print(f'Logged in successfully as {bot.user} with {bot.loaded} cogs')
if bot.__dict__.get("allow_running_cah_games", True):
await bot.change_presence(
status=discord.Status.online,
activity=discord.Activity(
name="your games of CAH",
type=discord.ActivityType.watching,
)
)
with open('token.txt') as tokens:
bot.tokens = classes.ObfuscatedDict(line.strip().split(":", 1) for line in tokens.readlines())
bot.loaded = 0
for position, cog in enumerate(cogs):
try:
bot.load_extension(cog)
bot.loaded += 1
print(f"Loaded {cog} (cog {position + 1}/{len(cogs)}, {bot.loaded} successful)")
except Exception as e:
print(f"Failed to load {cog} (cog {position + 1}/{len(cogs)}), Here's the error: {e}")
print("- [x] " + "".join(traceback.format_exc()).replace("\n", "\n- [x] "))
bot.run(bot.tokens["discord"])