-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
executable file
·302 lines (228 loc) · 14.8 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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# https://discord.com/api/oauth2/authorize?client_id=864797655443308564&permissions=8&scope=applications.commands%20bot
from bot import TuanAraiMaiRoo
import discord
import discord_slash
from discord_slash import SlashCommand
from discord_slash.model import SlashCommandOptionType
from src.utils.guilddata import *
from src.utils.kick import random_kick
from src.utils.travel import random_travel
from src.utils.command import SlashChoice from src.format.code import send_fmc # from src.server.Server import ku_verify, ku_info
from src.poker.poker import poker_play
from src.pog.pog import pog_play
from src.games import rockpaperscissors
from src.maths.maths import solve_eq
from src.audio.audio import say, play, disconnect
from discord_slash.utils.manage_commands import create_option, create_choice
from src.utils.member import getNick
from src.utils.env import vars
import pkg_resources
import platform
from datetime import datetime
pkg_resources.require("googletrans>=4.0.0-rc.1")
bot = TuanAraiMaiRoo()
slash = SlashCommand(bot, sync_commands=True)
ADMIN_ID = 186315352026644480
GUILD_IDS = None
@bot.event
async def on_ready():
global GUILD_IDS
print(datetime.now())
GUILD_IDS = [guild.id for guild in bot.guilds]
GUILD_NAMES = [guild.name for guild in bot.guilds]
print(GUILD_NAMES)
me = await bot.fetch_user(ADMIN_ID)
await me.send(f"Running {bot.user.name} on\n{platform.uname()}")
@bot.event
async def on_guild_join(guild):
global GuildData
global GuildIDs
if guild.id not in GuildIDs:
addGuild(guild.id)
print(f'added {guild.id} to guild db')
from src.utils.guilddata import GuildData, GuildIDs
@bot.event
async def on_message(msg: discord.Message):
global GuildData, GuildIDs
if msg.author.bot:
return
try:
if msg.guild.id not in GuildIDs:
addGuild(msg.guild.id)
print(f'added {msg.guild.id} to guild db')
from src.utils.guilddata import GuildData, GuildIDs
channel = msg.channel
guilddata = GuildData(msg.guild.id)
if channel.id in guilddata.codechannel_ids:
language = guilddata.channeldata(channel.id)['lang']
if msg.content[0] in ['_', '*', '`', ' ']:
return
await send_fmc(msg, language)
await msg.delete()
return
elif msg.content in guilddata.return_msg:
await channel.send(guilddata.return_msg[msg.content])
return
except:
pass
@slash.slash(name="hello", description="Say hi to the bot. Mo used to check if bot is ready.", guild_ids=GUILD_IDS)
async def nine_nine(ctx: discord_slash.SlashContext):
print(f'{str(ctx.author)} used {ctx.name}')
await ctx.send("HI :flushed:")
@slash.slash(name='invitebot', description='I will send you the authorization link, see you in your server.', guild_ids=GUILD_IDS)
async def send_botinvitelink(ctx: discord_slash.SlashContext):
await ctx.send('https://tinyurl.com/blackhole112')
@slash.subcommand(base='game', name="poker", description="Plays Poker.", guild_ids=GUILD_IDS)
async def _poker(ctx: discord_slash.SlashContext):
print(f'{str(ctx.author)} used {ctx.name}')
await poker_play(bot, ctx)
@slash.subcommand(base='game', name="pokdeng", description="Plays Pok Deng.", guild_ids=GUILD_IDS)
async def _pog(ctx: discord_slash.SlashContext):
print(f'{str(ctx.author)} used {ctx.name}')
await pog_play(bot, ctx)
@slash.subcommand(base='game', subcommand_group='rockpaperscissors', name='singleplayer',
description='Play Rock Paper Scissors with bot.', guild_ids=GUILD_IDS)
async def _rockpaperscissors(ctx: discord_slash.SlashContext):
print(f'{str(ctx.author)} used {ctx.name}')
await rockpaperscissors.RockPaperScissors.PlaySP(bot, ctx)
@slash.subcommand(base='game', subcommand_group='rockpaperscissors', name='multiplayer',
description='Play Rock Paper Scissors with friends.', guild_ids=GUILD_IDS)
async def _rockpaperscissors(ctx: discord_slash.SlashContext):
print(f'{str(ctx.author)} used {ctx.name}')
await rockpaperscissors.RockPaperScissors.PlayMP(bot, ctx)
@slash.slash(name="say", description="Say some thing(Text to speech)", guild_ids=GUILD_IDS,
options=[create_option(name='message',
description='The sound to play or the text for TTS',
option_type=SlashCommandOptionType.STRING, required=True),
create_option(name='language',
description='The language you want TTS to speak',
option_type=SlashCommandOptionType.STRING, required=False,
choices=SlashChoice.choiceVoiceLang)])
async def audio_say(ctx: discord_slash.SlashContext, message, language=None):
print(f'{str(ctx.author)} used {ctx.name}')
await say(bot, ctx, message, language)
@slash.slash(name="play", description="Play a sound", guild_ids=GUILD_IDS,
options=[create_option(name='sound',
description='Choose a sound to play.',
option_type=SlashCommandOptionType.STRING, required=True,
choices=SlashChoice.choiceSound)])
async def audio_play(ctx: discord_slash.SlashContext, sound):
print(f'{str(ctx.author)} used {ctx.name}')
await play(bot, ctx, sound)
@slash.slash(name="tu", description="ตู่", guild_ids=GUILD_IDS,
options=[create_option(name='sound',
description='[รายละเอียดถูกลบโดยรัฐบาลไทย]',
option_type=SlashCommandOptionType.STRING, required=True,
choices=SlashChoice.choiceTuVoice)])
async def audio_play(ctx: discord_slash.SlashContext, sound):
print(f'{str(ctx.author)} used {ctx.name}')
await play(bot, ctx, sound, political=True)
@slash.slash(name="pom", description="ป้อม", guild_ids=GUILD_IDS,
options=[create_option(name='sound',
description='[รายละเอียดถูกลบโดยรัฐบาลไทย]',
option_type=SlashCommandOptionType.STRING, required=True,
choices=SlashChoice.choicePomVoice)])
async def audio_play(ctx: discord_slash.SlashContext, sound):
print(f'{str(ctx.author)} used {ctx.name}')
await play(bot, ctx, sound, political=True)
@slash.subcommand(base='oneonetwo', name="o", description="112", guild_ids=GUILD_IDS,
options=[create_option(name='sound',
description='[รายละเอียดถูกลบโดยรัฐบาลไทย]',
option_type=SlashCommandOptionType.STRING, required=True,
choices=SlashChoice.choiceOVoice)])
async def audio_play(ctx: discord_slash.SlashContext, sound):
print(f'{str(ctx.author)} used {ctx.name}')
await play(bot, ctx, sound, political=True)
@slash.subcommand(base='oneonetwo', name="nui", description="112", guild_ids=GUILD_IDS,
options=[create_option(name='sound',
description='[รายละเอียดถูกลบโดยรัฐบาลไทย]',
option_type=SlashCommandOptionType.STRING, required=True,
choices=SlashChoice.choiceNuiVoice)])
async def audio_play(ctx: discord_slash.SlashContext, sound):
print(f'{str(ctx.author)} used {ctx.name}')
await play(bot, ctx, sound, political=True)
@slash.subcommand(base='oneonetwo', name="pui", description="112", guild_ids=GUILD_IDS,
options=[create_option(name='sound',
description='[รายละเอียดถูกลบโดยรัฐบาลไทย]',
option_type=SlashCommandOptionType.STRING, required=True,
choices=SlashChoice.choicePuiVoice)])
async def audio_play(ctx: discord_slash.SlashContext, sound):
print(f'{str(ctx.author)} used {ctx.name}')
await play(bot, ctx, sound, political=True)
@slash.slash(name='n', description='Play N Sound for user [Warning! This sound can hurt your ears].', guild_ids=GUILD_IDS,
options=[create_option(name='sound',
description='Select Sound To play',
option_type=SlashCommandOptionType.STRING, required=True,
choices=SlashChoice.choiceNVoice)])
async def audio_play(ctx: discord_slash.SlashContext, sound: str):
print(f'{str(ctx.author)} used {ctx.name}')
await play(bot, ctx, sound)
@slash.slash(name='slap', description='Slap.', guild_ids=GUILD_IDS)
async def audio_play(ctx: discord_slash.SlashContext):
print(f'{str(ctx.author)} used {ctx.name}')
await play(bot, ctx, 'slap')
@slash.slash(name="disconnect", description="Disconnect bot from the Voice Channel", guild_ids=GUILD_IDS)
async def audio_disconnect(ctx: discord_slash.SlashContext):
print(f'{str(ctx.author)} used {ctx.name}')
await disconnect(bot, ctx)
@slash.slash(name="snap", description="Perfectly balanced, as all things should be", guild_ids=GUILD_IDS)
async def snap_kick(ctx: discord_slash.SlashContext, user: discord.Member = None):
print(f'{str(ctx.author)} used {ctx.name}')
await random_kick(bot, ctx, user)
@slash.slash(name='travel', description="Travel to all of the Voice Channel.", guild_ids=GUILD_IDS)
async def travel_chanel(ctx: discord_slash.SlashContext, user: discord.Member = None):
print(f'{str(ctx.author)} used {ctx.name}')
await random_travel(bot, ctx, user)
@slash.subcommand(base='codechannel', name='add', description='Add auto text formatting to a text channel.', guild_ids=GUILD_IDS,
options=[create_option(name='channel', description='The channel you want to add text formatting to.',
option_type=SlashCommandOptionType.CHANNEL, required=True),
create_option(name='language', description='The programming language for text formatting on this channel.',
option_type=SlashCommandOptionType.STRING, required=True,
choices=SlashChoice.programmingLanguageChoice)])
async def _codechannel_add(ctx: discord_slash.SlashContext, channel: discord.TextChannel, language: str):
await AddCodeChannel(ctx, channel, language)
@slash.subcommand(base='codechannel', name='remove', description='Add auto text formatting to a text channel.', guild_ids=GUILD_IDS,
options=[create_option(name='channel', description='The channel you want to remove text formatting from.',
option_type=SlashCommandOptionType.CHANNEL, required=True,)])
async def _codechannel_remove(ctx: discord_slash.SlashContext, channel: discord.TextChannel):
await RemoveCodeChannel(ctx, channel)
@slash.subcommand(base='codechannel', name='list', description='list all code channel in this server.', guild_ids=GUILD_IDS)
async def _codechannel_check(ctx: discord_slash.SlashContext):
await ListCodeChannel(ctx)
@slash.subcommand(base='codechannel', subcommand_group='permission', name='managemessage', description='Set Manage Messages permission of a/all code channel(s).', guild_ids=GUILD_IDS,
options=[create_option(name='channel', description='Choose a code channel| All code channels.',
option_type=SlashCommandOptionType.CHANNEL, required=True),
create_option(name='manageable', description='manageable or not.',
option_type=SlashCommandOptionType.BOOLEAN, required=True)])
async def _codechannel_permission_managemessage(ctx: discord_slash.SlashContext, channel: discord.TextChannel, manageable: bool):
await Permission.ManageMessage(ctx, manageable, channel)
@slash.subcommand(base='return', name='add', description='Add return messages. (Teach the bot.)', guild_ids=GUILD_IDS,
options=[create_option(name='message', description='-',
option_type=SlashCommandOptionType.STRING, required=True),
create_option(name='return_message', description='The message that you want the bot to say in return.',
option_type=SlashCommandOptionType.STRING, required=True)])
async def _returnmsg_add(ctx: discord_slash.SlashContext, message: str, return_message: str):
await AddReturnMsg(ctx, message, return_message)
@slash.subcommand(base='return', name='remove', description="Remove return messages. (Delete the bot's memory.)", guild_ids=GUILD_IDS,
options=[create_option(name='message', description='The message that you want to delete.',
option_type=SlashCommandOptionType.STRING, required=True)])
async def _returnmsg_add(ctx: discord_slash.SlashContext, message: str):
await RemoveReturnMsg(ctx, message)
# @slash.slash(name='verify', description='Verifies that you are a true KU student', guild_ids=[847172394316464178, 440532168389689345])
# async def _verify(ctx: discord_slash.SlashContext):
# await ctx.send(f"Verify is dead.")
# @slash.slash(name='info', description='Shows KU info of a user.', guild_ids=GUILD_IDS)
# async def _info(ctx: discord_slash.SlashContext, user: discord.Member = None):
# msg = await ctx.send('Processing..')
# await msg.edit(content="", embed=ku_info(ctx, user))
@slash.subcommand(base='math', name='solve', description='Solve an equation.', guild_ids=GUILD_IDS,
options=[create_option(name='equation', description='The equation you want to solve. (If possible, move the expression after (=) aside)',
option_type=SlashCommandOptionType.STRING, required=True),
create_option(name='variable', description='The variable you want to solve for.',
option_type=SlashCommandOptionType.STRING, required=False),
create_option(name='foregroundcolor', description='Foreground Color.',
option_type=SlashCommandOptionType.STRING, required=False,
choices=[create_choice("White", "White"), create_choice("Black", "Black")])])
async def _math_solve(ctx: discord_slash.SlashContext, equation: str, variable: str = None, color: str = "White"):
await solve_eq(ctx, equation, variable, color)
bot.run(vars.TOKEN)