-
Notifications
You must be signed in to change notification settings - Fork 11
/
TekkenBot.py
277 lines (221 loc) · 9.3 KB
/
TekkenBot.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
import discord
import asyncio
import logging
from discord.ext import commands
# self-created modules below
import lib.embedCreation as embedCreation #contains functions for creating an embed
import lib.tekkenFinder as tekkenFinder #contains functions for finding character and move details
# Get token from local dir text file
tokenFile = open("token.txt", 'r')
token = tokenFile.read()
tokenFile.close()
description = 'A Tekken 7 Frame Data Bot made by Hann.'
prefix = '.'
discord_logger = logging.getLogger('discord')
discord_logger.setLevel(logging.CRITICAL)
log = logging.getLogger()
log.setLevel(logging.INFO)
handler = logging.FileHandler(filename='combot.log', encoding='utf-8', mode='w')
log.addHandler(handler)
bot = commands.Bot(command_prefix=prefix, description=description)
combot_gagged_channels_File = open("lib/gagged_channels.txt", 'r')
combot_gagged_channels = combot_gagged_channels_File.read().splitlines()
combot_gagged_channels_File.close()
# TODO: YOU LEFT OFF HERE
# TODO: MAYBE NEXT TIME FAM
# file = open('bot_settings.json', 'r+')
# content = file.read()
# file.close()
# stuff = content.loads(content)
@bot.event
async def on_ready():
# Display Login Status in Console
print('<---------------------------->')
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('<---------------------------->')
while True:
await bot.change_presence(game=discord.Game(name='DAH'))
await asyncio.sleep(30)
await bot.change_presence(game=discord.Game(name='.help'))
await asyncio.sleep(120)
await bot.change_presence(game=discord.Game(name='Riri Toppu Tieru'))
await asyncio.sleep(30)
await bot.change_presence(game=discord.Game(name='TEKKEN 7'))
await asyncio.sleep(30)
@bot.event
async def on_message(message):
# check if message author is a bot
if message.author.bot:
# check if sent by self
if message.author.id == bot.user.id:
await bot_message_cleanup(message)
return
if await is_Gagged(message):
return
if message.content.startswith('!'):
if message.content.startswith('!!'):
case_sensitive_toggle = True
else:
case_sensitive_toggle = False
# message content should look like this
# ![character] [move]
userMessage = message.content
userMessage = userMessage.replace("!", "")
user_message_list = userMessage.split(" ", 1)
if len(user_message_list) <= 1:
print('! command used, but character not found/move not given\n')
return
user_Chara_Name = user_message_list[0]
user_Chara_Move = user_message_list[1]
#TODO: IMPLEMENT CHARACTER SHORTHAND NAME CONVERTER, OR CHARACTER NAMELIST DISPLAY
character_name_string = tekkenFinder.does_char_exist(user_Chara_Name)
if character_name_string:
user_Chara_Name = character_name_string.lower()
move_attribute_dict = tekkenFinder.get_Move_Details(user_Chara_Name,
user_Chara_Move,
case_sensitive_toggle)
if move_attribute_dict: # if dictionary not empty, move found
embed_MoveFound = await get_MoveFound_Embed(**move_attribute_dict)
await bot.send_message(message.channel, embed=embed_MoveFound)
else: # dictionary is empty, move not found
embed_SimilarMoves = await get_SimilarMoves_Embed(user_Chara_Name,user_Chara_Move)
await bot.send_message(message.channel, embed=embed_SimilarMoves)
await user_message_cleanup(message)
return
else:
await bot.send_message(message.channel, 'Character not found: ' + '**' + user_Chara_Name + '**')
return
await bot.process_commands(message)
@bot.command(pass_context=True)
async def legend(ctx):
"""Displays commonly used abbreviations, notations and their corresponding input icons."""
embed_legend = embedCreation.embed_legend()
await bot.say(embed=embed_legend)
await user_message_cleanup(ctx.message)
@bot.command(pass_context=True)
@commands.has_permissions(administrator=True)
async def gagcombot(ctx):
"""Gags Combot in this channel. Usable only by admin roles."""
channel = ctx.message.channel.id
combot_gagged_channels.append(channel)
f = open("lib/gagged_channels.txt","a")
f.write(channel + '\n')
f.close()
await bot.say('Mmmph! Gagging Combot.')
@bot.command(pass_context=True)
@commands.has_permissions(administrator=True)
async def ungagcombot(ctx):
"""Ungags Combot in this channel. Usable only by server admins."""
channel = ctx.message.channel.id
if channel in combot_gagged_channels:
combot_gagged_channels.remove(channel)
else:
return
# clear file contents and rewrite
open("lib/gagged_channels.txt", "w").close()
f = open("lib/gagged_channels.txt", "a")
for channel in combot_gagged_channels:
f.write(channel+'\n')
f.close()
await bot.say('Ungagged Combot. Beep Boop.')
@bot.command(pass_context=True)
async def printServers(ctx):
"""List servers with Combot. Cmd restricted to Bot Owner."""
appinfo = await bot.application_info()
owner = appinfo.owner.id
if ctx.message.author.id != owner:
print('Non-bot owner called print server.')
await bot.say('Command restricted to bot owner only.')
await user_message_cleanup(ctx.message)
return
else:
print('Bot Owner called print server.')
serverConctStr = ''
for server in bot.servers:
serverConctStr = serverConctStr + server.name + '\n'
await bot.say('Server List: \n' + serverConctStr)
await user_message_cleanup(ctx.message)
@bot.command(pass_context=True)
async def Frame_Data(ctx):
"""Use ![character] [move], !! for case-sensitive search"""
await user_message_cleanup(ctx.message)
return
@bot.command(pass_context=True)
async def invite(ctx):
"""Invite the bot to your server."""
await bot.say('Use this link to add me to your server. \nhttps://discordapp.com/oauth2/authorize?client_id=302295833208946689&scope=bot&permissions=11264')
await user_message_cleanup(ctx.message)
return
# This block of code to be used when character html pages are updated, do not edit
@bot.command(pass_context=True)
async def convertAll(ctx):
"""Converts all """
appinfo = await bot.application_info()
owner = appinfo.owner.id
if ctx.message.author.id != owner:
return
else:
await bot.say('Converting all character htmls to json.')
tekkenFinder.charJsonMassConverter()
return
@bot.event
async def on_command_error(error, ctx):
if isinstance(error, commands.CheckFailure):
await bot.send_message(ctx.message.channel, "You don't have permissions to run this.")
# ==============================================
# ==========NON COMMAND FUNCTIONS===============
# ==============================================
async def bot_message_cleanup(message):
TZ_Server_ID = '165310633884123137'
TZ_FrameChannel_ID = '315052762947649536'
TestServer_Server_ID = '302481884984639488'
TestServer_ChannelID = '303175029884059649'
Delay_Seconds = 10
if message.channel.is_private or message.channel.id == TZ_FrameChannel_ID:
# lazy workaround for TZ's frame data channel cuz ppl spam shit in chara channels
# dont do shit
return
if message.server.id == TZ_Server_ID:
# lazy workaround No.2
await asyncio.sleep(Delay_Seconds)
await bot.delete_message(message)
return
if message.channel.permissions_for(message.server.me).manage_messages:
# self delete does not require server permissions,
# but tying both cleanups to one check for now until I make a controllable toggle.
await asyncio.sleep(Delay_Seconds)
await bot.delete_message(message)
return
async def user_message_cleanup(message):
Delay_Seconds = 15
if message.channel.is_private:
return
if message.channel.permissions_for(message.server.me).manage_messages:
await asyncio.sleep(Delay_Seconds)
await bot.delete_message(message)
async def is_Gagged(user_message):
message = user_message
# check if channel is gagged
if message.content != '.ungagcombot':
for channelID in combot_gagged_channels:
if message.channel.id == channelID:
return True
return False
async def get_MoveFound_Embed(**move_attribute_dict):
misc_details_Dict = tekkenFinder.get_Misc_Chara_Details(move_attribute_dict['char_name'])
embedDict = {**move_attribute_dict, **misc_details_Dict}
embed_MoveFound = embedCreation.embed_Move_Details(**embedDict)
return embed_MoveFound
async def get_SimilarMoves_Embed(user_Chara_Name, user_Chara_Move):
misc_details_Dict = tekkenFinder.get_Misc_Chara_Details(user_Chara_Name)
similar_moves_list = tekkenFinder.get_Similar_Moves(user_Chara_Name, user_Chara_Move)
embed_SimilarMoves = embedCreation.embed_Similar_Moves(similar_moves_list, user_Chara_Name, **misc_details_Dict)
return embed_SimilarMoves
#Starts the bot
bot.run(token)
handlers = log.handlers[:]
for hdlr in handlers:
hdlr.close()
log.removeHandler(hdlr)