-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
82 lines (77 loc) · 2.41 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
import discord
import pycld2 as cld2
import os
import ctypes
import rebuilder
from keep_alive import keep_alive
rebuilder.exec("gcc -fPIC -c dstrcat.c -o dstrcat.o -DDEBUG_LVL=0")
rebuilder.exec("gcc -fPIC -c copy_file.c -o copy_file.o")
rebuilder.exec("gcc -fPIC -c charsheet_utils.c -o charsheet_utils.o")
rebuilder.exec(
"gcc -fPIC -c dndml/dnd_input_reader.c "
"-o dndml/dnd_input_reader.o"
)
rebuilder.exec(
"gcc -fPIC -c dndml/dnd_lexer.c "
"-o dndml/dnd_lexer.o"
)
rebuilder.exec(
"gcc -fPIC -c dndml/dnd_charsheet.c -DDEBUG_LVL=0 "
"-o dndml/dnd_charsheet.o"
)
rebuilder.exec(
"gcc -fPIC -c dndml/dnd_parser.c -DDEBUG_LVL=0 "
"-o dndml/dnd_parser.o"
)
rebuilder.exec(
"gcc -fPIC -shared tryptobot.c "
"dstrcat.o "
"dndml/dnd_input_reader.o "
"dndml/dnd_lexer.o "
"dndml/dnd_charsheet.o "
"dndml/dnd_parser.o "
"charsheet_utils.o "
"copy_file.o "
"-o libtryptobot.so -lm"
)
print("Recompiled `libtryptobot.so`.")
libc = ctypes.CDLL("libc.so.6")
libtrypto = ctypes.CDLL("./libtryptobot.so")
libtrypto.handle_message.argtypes = (ctypes.c_char_p,)
libtrypto.handle_message.restype = ctypes.POINTER(ctypes.c_char)
client = discord.Client()
@client.event
async def on_ready():
print("Tryptobot online")
print(client.user)
@client.event
async def on_message(message):
if message.author != client.user and message.author.name != "Carl-bot":
if message.channel.id == 939263185712721950:
lang = cld2.detect(message.content)[2][0][0]
if lang == "ENGLISH":
await message.delete()
await message.author.send(
"Il est interdit d'envoyer des messages "
"en anglais sur le canal #langues-étrangères."
)
if message.content.lower() == "gm":
await message.channel.send(f"Good morning, {message.author.mention}!")
if len(message.content) > 0 and message.content[0] == '%':
if message.content[1:6] == "bonk ":
horny_user = message.content[6:]
await message.channel.send(f"{horny_user} go to horny jail", file=discord.File("cheems.png"))
else:
result = libtrypto.handle_message(
ctypes.c_char_p(bytes(message.content, encoding="utf-8"))
)
await message.channel.send(
ctypes.cast(result, ctypes.c_char_p).value.decode()
)
libc.free(result)
keep_alive()
token = os.environ.get("DISCORD_BOT_SECRET")
try:
client.run(token)
except:
os.system("kill 1") # restart the server