Fetch custom rewards from database rather than hard coded
This commit is contained in:
parent
8cfc10c039
commit
87c5fd1abf
1 changed files with 9 additions and 11 deletions
20
bot.py
20
bot.py
|
@ -17,6 +17,7 @@ class Bot(commands.Bot):
|
||||||
self.db_cur = self.db_con.cursor()
|
self.db_cur = self.db_con.cursor()
|
||||||
|
|
||||||
self.db_cur.execute("CREATE TABLE IF NOT EXISTS custom_commands(command TEXT, output_text TEXT, author TEXT)")
|
self.db_cur.execute("CREATE TABLE IF NOT EXISTS custom_commands(command TEXT, output_text TEXT, author TEXT)")
|
||||||
|
self.db_cur.execute("CREATE TABLE IF NOT EXISTS channel_reward_messages(title TEXT, output_text TEXT)")
|
||||||
print("Created database table")
|
print("Created database table")
|
||||||
commands = self.db_cur.execute("SELECT count(*) FROM custom_commands").fetchone()
|
commands = self.db_cur.execute("SELECT count(*) FROM custom_commands").fetchone()
|
||||||
print(f"{commands[0]} custom commands available")
|
print(f"{commands[0]} custom commands available")
|
||||||
|
@ -58,17 +59,14 @@ class Bot(commands.Bot):
|
||||||
# Can I put this function somewhere else LMAO
|
# Can I put this function somewhere else LMAO
|
||||||
@self.event()
|
@self.event()
|
||||||
async def event_pubsub_channel_points(event: pubsub.PubSubChannelPointsMessage):
|
async def event_pubsub_channel_points(event: pubsub.PubSubChannelPointsMessage):
|
||||||
reward = event.reward.title
|
reward_title = event.reward.title
|
||||||
channel = self.get_channel(os.environ["CHANNEL"])
|
result = self.db_cur.execute("SELECT output_text FROM channel_reward_messages WHERE title=?", [reward_title]).fetchone()
|
||||||
if reward == "nice":
|
if result is not None:
|
||||||
await channel.send(f"@{event.user.name} nice")
|
message = result[0]
|
||||||
elif reward == "very nice":
|
message = message.replace("%USER%", event.user.name)
|
||||||
await channel.send(f"@{event.user.name} very nice")
|
if event.input:
|
||||||
elif reward == "Add a custom command to my bot!":
|
message = message.replace("%INPUT%", event.input)
|
||||||
await channel.send(f"{event.user.name} redeemed a custom command!")
|
await self.get_channel(os.environ["CHANNEL"]).send(message)
|
||||||
await self.add_custom_command(channel, event.input, event.user.name)
|
|
||||||
else:
|
|
||||||
await channel.send(f"{event.user.name} redeemed {event.input}!")
|
|
||||||
|
|
||||||
async def event_message(self, message):
|
async def event_message(self, message):
|
||||||
if message.echo:
|
if message.echo:
|
||||||
|
|
Loading…
Add table
Reference in a new issue