forked from nh-server/Kurisu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·153 lines (133 loc) · 5.18 KB
/
run.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python3
# Kurisu by 916253 & ihaveamac
# license: Apache License 2.0
# https://github.com/916253/Kurisu
description = """
Kurisu, the bot for the 3DS Hacking Discord!
"""
# import dependencies
import os
from discord.ext import commands
import discord
import datetime, re
import json, asyncio
import copy
import configparser
import traceback
import sys
import os
# sets working directory to bot's folder
dir_path = os.path.dirname(os.path.realpath(__file__))
os.chdir(dir_path)
# read config for token
config = configparser.ConfigParser()
config.read("config.ini")
# create warns.json if it doesn't exist
if not os.path.isfile("warns.json"):
with open("warns.json", "w") as f:
f.write("{}")
# create restrictions.json if it doesn't exist
if not os.path.isfile("restrictions.json"):
with open("restrictions.json", "w") as f:
f.write("{}")
# create staff.json if it doesn't exist
if not os.path.isfile("staff.json"):
with open("staff.json", "w") as f:
f.write("{}")
# create helpers.json if it doesn't exist
if not os.path.isfile("helpers.json"):
with open("helpers.json", "w") as f:
f.write("{}")
# create timebans.json if it doesn't exist
if not os.path.isfile("timebans.json"):
with open("timebans.json", "w") as f:
f.write("{}")
# create watch.json if it doesn't exist
if not os.path.isfile("watch.json"):
with open("watch.json", "w") as f:
f.write("{}")
prefix = ['!', '.']
bot = commands.Bot(command_prefix=prefix, description=description, pm_help=None)
bot.actions = [] # changes messages in mod-/server-logs
with open("watch.json", "r") as f:
bot.watching = json.load(f) # post user messages to messaage-logs
# http://stackoverflow.com/questions/3411771/multiple-character-replace-with-python
chars = "\\`*_<>#@:"
def escape_name(name):
name = str(name)
for c in chars:
if c in name:
name = name.replace(c, "\\" + c)
return name.replace("@", "@\u200b") # prevent mentions
bot.escape_name = escape_name
bot.pruning = False # used to disable leave logs if pruning, maybe.
@bot.event
async def on_ready():
# this bot should only ever be in one server anyway
for server in bot.servers:
print("{} has started! {} has {:,} members!".format(bot.user.name, server.name, server.member_count))
bot.server = server
# channels
bot.welcome_channel = discord.utils.get(server.channels, name="welcome-and-rules")
bot.announcements_channel = discord.utils.get(server.channels, name="announcements")
bot.helpers_channel = discord.utils.get(server.channels, name="helpers")
bot.mods_channel = discord.utils.get(server.channels, name="mods")
bot.modlogs_channel = discord.utils.get(server.channels, name="mod-logs")
bot.serverlogs_channel = discord.utils.get(server.channels, name="server-logs")
bot.messagelogs_channel = discord.utils.get(server.channels, name="message-logs")
# roles
bot.staff_role = discord.utils.get(server.roles, name="Staff")
bot.halfop_role = discord.utils.get(server.roles, name="HalfOP")
bot.op_role = discord.utils.get(server.roles, name="OP")
bot.superop_role = discord.utils.get(server.roles, name="SuperOP")
bot.helpers_role = discord.utils.get(server.roles, name="Helpers")
bot.onduty_role = discord.utils.get(server.roles, name="On-Duty")
bot.verified_role = discord.utils.get(server.roles, name="Verified")
bot.trusted_role = discord.utils.get(server.roles, name="Trusted")
bot.probation_role = discord.utils.get(server.roles, name="Probation")
bot.muted_role = discord.utils.get(server.roles, name="Muted")
bot.nomemes_role = discord.utils.get(server.roles, name="No-Memes")
bot.nohelp_role = discord.utils.get(server.roles, name="No-Help")
bot.noembed_role = discord.utils.get(server.roles, name="No-Embed")
bot.elsewhere_role = discord.utils.get(server.roles, name="#elsewhere")
bot.everyone_role = discord.utils.get(server.roles, name="@everyone")
msg = "{} has started! {} has {:,} members!".format(bot.user.name, server.name, server.member_count)
if len(failed_addons) != 0:
msg += "\n\nSome addons failed to load:\n"
for f in failed_addons:
msg += "\n{}: `{}: {}`".format(*f)
await bot.send_message(bot.helpers_channel, msg)
break
# loads extensions
addons = [
'addons.assistance',
'addons.blah',
'addons.ctrerr',
'addons.events',
'addons.extras',
'addons.friendcode',
'addons.kickban',
'addons.load',
'addons.lockdown',
'addons.logs',
'addons.loop',
'addons.memes',
'addons.helper_list',
'addons.mod_staff',
'addons.mod_warn',
'addons.mod_watch',
'addons.mod',
'addons.ninerr',
'addons.rules',
'addons.xkcdparse',
]
failed_addons = []
for extension in addons:
try:
bot.load_extension(extension)
except Exception as e:
print('{} failed to load.\n{}: {}'.format(extension, type(e).__name__, e))
failed_addons.append([extension, type(e).__name__, e])
# Execute
print('Bot directory: ', dir_path)
bot.run(config['Main']['token'])