Skip to content

Commit 7a7d545

Browse files
committed
Manipulated events
Signed-off-by: ColaIan <colaian.yt@gmail.com>
1 parent ca55738 commit 7a7d545

File tree

5 files changed

+67
-44
lines changed

5 files changed

+67
-44
lines changed

Teapot.py

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88

99
import teapot
1010

11-
print("""
11+
print(f"""
1212
_____ _
1313
|_ _|__ __ _ _ __ ___ | |_
14-
| |/ _ \/ _` | '_ \ / _ \| __|
14+
| |/ _ \\/ _` | '_ \\ / _ \\| __|
1515
| | __/ (_| | |_) | (_) | |_
16-
|_|\___|\__,_| .__/ \___/ \__|
16+
|_|\\___|\\__,_| .__/ \\___/ \\__|
1717
by ColaIan |_| & RedTea
18+
19+
Running Teapot.pt {teapot.version()}
1820
""")
1921

2022
load_dotenv(join(dirname(__file__), '.env'))
@@ -34,8 +36,14 @@
3436
db.execute('CREATE TABLE IF NOT EXISTS `guilds` (`guild_id` BIGINT, `guild_name` TINYTEXT)')
3537
db.execute('CREATE TABLE IF NOT EXISTS `channels` (`channel_id` BIGINT, `channel_name` TINYTEXT)')
3638
db.execute("CREATE TABLE IF NOT EXISTS `users` (`user_id` BIGINT, `user_name` TINYTEXT, `user_discriminator` INT)")
39+
db.execute("CREATE TABLE IF NOT EXISTS `logs` (`timestamp` TEXT, `type` TINYTEXT, `class` TINYTEXT, `message` "
40+
"MEDIUMTEXT)")
3741
print(f"Connected to database ({teapot.config.db_host()}) in {round(time.perf_counter() - time_start, 2)}s")
3842

43+
db.execute("INSERT INTO `logs`(timestamp, type, class, message) VALUES(%s, %s, %s, %s)",
44+
(teapot.time(), "BOT_START", __name__, "Initialized bot"))
45+
database.commit()
46+
3947
bot = dcmd.Bot(command_prefix=teapot.config.bot_prefix())
4048

4149

@@ -59,35 +67,12 @@ async def on_ready():
5967
await bot.change_presence(status=discord.Status.online, activity=discord.Game(teapot.config.bot_status()))
6068

6169

62-
@bot.event
63-
async def on_message(message):
64-
guild = message.guild
65-
if teapot.config.storage_type() == "mysql":
66-
try:
67-
db.execute("SELECT * FROM `users` WHERE user_id = '" + str(message.author.id) + "'")
68-
if db.rowcount == 0:
69-
db.execute("INSERT INTO `users`(user_id, user_name, user_discriminator) VALUES(%s, %s, %s)",
70-
(message.author.id, message.author.name, message.author.discriminator.zfill(4)))
71-
database.commit()
72-
73-
db.execute("SELECT * FROM `channels` WHERE channel_id = '" + str(message.channel.id) + "'")
74-
if db.rowcount == 0:
75-
db.execute("INSERT INTO `channels`(channel_id, channel_name) VALUES(%s, %s)",
76-
(message.channel.id, message.channel.name))
77-
database.commit()
78-
db.execute("INSERT INTO `" + str(
79-
guild.id) + "_logs" + "`(timestamp, guild_id, channel_id, message_id, user_id, action_type, message) VALUES(%s, %s, %s, %s, %s, %s, %s)",
80-
(teapot.time(), message.guild.id, message.channel.id, message.id, message.author.id,
81-
"MESSAGE_SEND", message.content))
82-
database.commit()
83-
except Exception as e:
84-
print(e)
85-
await bot.process_commands(message)
86-
8770

8871
try:
8972
discord_time_start = time.perf_counter()
9073
bot.run(teapot.config.bot_token())
9174
except Exception as e:
92-
print(e)
93-
print("[/!\] Failed to connect to DiscordAPI. Please check your bot token!")
75+
print(f"[/!\\] Failed to connect to DiscordAPI. Please check your bot token!\n{e}")
76+
if teapot.config.storage_type() == "mysql":
77+
db.execute("INSERT INTO `logs`(timestamp, type, class, message) VALUES(%s, %s, %s, %s)",
78+
(teapot.time(), "ERROR", __name__, e))

teapot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
def version():
11-
return "0.0.1"
11+
return "v0.0.1.4"
1212

1313

1414
def config_version():

teapot/cogs/cmds.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def helpcmd(bot):
2222
async def help(ctx):
2323
embed = discord.Embed(title="Command List", description="List of commands that you can use",
2424
color=0x7400FF)
25-
embed.set_author(name=f"Teapot.py | {teapot.version()}",
25+
embed.set_author(name=f"Teapot.py {teapot.version()}",
2626
icon_url="https://cdn.discordapp.com/avatars/612634758744113182/7fe078b5ea6b43000dfb7964e3e4d21d.png?size=512")
2727
embed.set_thumbnail(url="https://avatars2.githubusercontent.com/u/60006969?s=200&v=4")
2828
embed.add_field(name="General", value="``help``, ``info``", inline=False)
@@ -47,7 +47,7 @@ def info(bot):
4747
async def info(ctx):
4848
embed = discord.Embed(title="Developers: ColaIan, RedTea", description="Multi-purpose Discord Bot",
4949
color=0x7400FF)
50-
embed.set_author(name=f"Teapot.py | {teapot.version()}",
50+
embed.set_author(name=f"Teapot.py {teapot.version()}",
5151
icon_url="https://cdn.discordapp.com/avatars/612634758744113182/7fe078b5ea6b43000dfb7964e3e4d21d.png?size=512")
5252
embed.set_thumbnail(url="https://avatars2.githubusercontent.com/u/60006969?s=200&v=4")
5353
embed.add_field(name="Bot User:", value=bot.user, inline=True)

teapot/events.py

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ def __init__(bot):
77
""" Initialize events """
88
join(bot)
99
leave(bot)
10-
on_command_error(bot)
10+
on_guild_join(bot)
11+
message_send(bot)
1112
message_edit(bot)
1213
message_delete(bot)
14+
on_command_error(bot)
1315

1416

1517
def join(bot):
@@ -42,20 +44,40 @@ async def on_member_remove(member):
4244
print(e)
4345

4446

45-
def on_command_error(bot):
47+
def on_guild_join(bot):
4648
@bot.event
47-
async def on_command_error(ctx, error):
49+
async def on_guild_join(ctx):
50+
if teapot.config.storage_type() == "mysql":
51+
teapot.database.create_guild_table(ctx.guild)
52+
53+
54+
def message_send(bot):
55+
@bot.event
56+
async def on_message(message):
57+
guild = message.guild
4858
if teapot.config.storage_type() == "mysql":
4959
try:
5060
database = teapot.database.__init__()
5161
db = teapot.database.db(database)
52-
db.execute("INSERT INTO " + str(
53-
ctx.guild.id) + "_logs" + "(timestamp, guild_id, channel_id, message_id, user_id, action_type, message) VALUES(%s, %s, %s, %s, %s, %s, %s)",
54-
(teapot.time(), ctx.guild.id, ctx.message.channel.id, ctx.message.id, ctx.message.author.id,
55-
"CMD_ERROR", str(error)))
62+
db.execute("SELECT * FROM `users` WHERE user_id = '" + str(message.author.id) + "'")
63+
if db.rowcount == 0:
64+
db.execute("INSERT INTO `users`(user_id, user_name, user_discriminator) VALUES(%s, %s, %s)",
65+
(message.author.id, message.author.name, message.author.discriminator.zfill(4)))
66+
database.commit()
67+
68+
db.execute("SELECT * FROM `channels` WHERE channel_id = '" + str(message.channel.id) + "'")
69+
if db.rowcount == 0:
70+
db.execute("INSERT INTO `channels`(channel_id, channel_name) VALUES(%s, %s)",
71+
(message.channel.id, message.channel.name))
72+
database.commit()
73+
db.execute("INSERT INTO `" + str(
74+
guild.id) + "_logs" + "`(timestamp, guild_id, channel_id, message_id, user_id, action_type, message) VALUES(%s, %s, %s, %s, %s, %s, %s)",
75+
(teapot.time(), message.guild.id, message.channel.id, message.id, message.author.id,
76+
"MESSAGE_SEND", message.content))
5677
database.commit()
5778
except Exception as e:
5879
print(e)
80+
await bot.process_commands(message)
5981

6082

6183
def message_edit(bot):
@@ -110,3 +132,19 @@ async def on_message_delete(ctx):
110132
print(e)
111133
elif teapot.config.storage_type() == "flatfile":
112134
pass
135+
136+
137+
def on_command_error(bot):
138+
@bot.event
139+
async def on_command_error(ctx, error):
140+
if teapot.config.storage_type() == "mysql":
141+
try:
142+
database = teapot.database.__init__()
143+
db = teapot.database.db(database)
144+
db.execute("INSERT INTO " + str(
145+
ctx.guild.id) + "_logs" + "(timestamp, guild_id, channel_id, message_id, user_id, action_type, message) VALUES(%s, %s, %s, %s, %s, %s, %s)",
146+
(teapot.time(), ctx.guild.id, ctx.message.channel.id, ctx.message.id, ctx.message.author.id,
147+
"CMD_ERROR", str(error)))
148+
database.commit()
149+
except Exception as e:
150+
print(e)

teapot/setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ def __init__():
99
1010
_____ _ ____ __ _ _
1111
|_ _|__ __ _ _ __ ___ | |_ / ___|___ _ __ / _(_) __ _ _ _ _ __ __ _| |_ ___ _ __
12-
| |/ _ \/ _` | '_ \ / _ \| __| | | / _ \| '_ \| |_| |/ _` | | | | '__/ _` | __/ _ \| '__|
12+
| |/ _ \\/ _` | '_ \\ / _ \\| __| | | / _ \\| '_ \\| |_| |/ _` | | | | '__/ _` | __/ _ \\| '__|
1313
| | __/ (_| | |_) | (_) | |_ | |__| (_) | | | | _| | (_| | |_| | | | (_| | || (_) | |
14-
|_|\___|\__,_| .__/ \___/ \__| \____\___/|_| |_|_| |_|\__, |\__,_|_| \__,_|\__\___/|_|
14+
|_|\\___|\\__,_| .__/ \\___/ \\__| \\____\\___/|_| |_|_| |_|\\__, |\\__,_|_| \\__,_|\\__\\___/|_|
1515
|_| by ColaIan and RedTea |___/
1616
1717
NOTE: You can change the settings later in .env :3
@@ -73,6 +73,6 @@ def __init__():
7373
print("Setup complete!")
7474
time.sleep(5)
7575
print('\n' * 100)
76-
except Exception as error:
77-
print("\n[!] An error occurred when creating config file.\n" + str(error))
76+
except Exception as e:
77+
print("\n[!] An error occurred when creating config file.\n" + str(e))
7878
quit()

0 commit comments

Comments
 (0)