Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Ghodawalaaman/05c0513afcc32e3a09e35d7253b3f90b to your computer and use it in GitHub Desktop.
Save Ghodawalaaman/05c0513afcc32e3a09e35d7253b3f90b to your computer and use it in GitHub Desktop.
sqlite3 query eval bot in python
import pydle
import sqlite3
import requests as req
import os
# Simple echo bot.
class MyOwnBot(pydle.Client):
async def on_connect(self):
await self.join('#bottest')
await self.join('#bsah')
async def on_message(self, target, source, message):
if message.startswith("!query"):
query = message.split("!query")[1]
conn = sqlite3.connect("file:./irc_log.sqlite3?mode=ro")
cur = conn.cursor()
try:
cur.execute(query)
except Exception as e:
await self.message(target, str(e))
return
conn.commit()
print(f"query is: ", query)
query_output = cur.fetchall()
for row in query_output[0:1]:
await self.message(target, (' '.join(str(item) for item in row)).replace("\n"," "))
with open("/tmp/query_output.txt", 'w') as f:
for row in query_output:
f.write(' '.join(str(item) for item in row)+'\n')
link = os.popen("./upload_query.sh").read().replace('\n','')
await self.message(target, link)
conn.close()
client = MyOwnBot('I_am_bot_hehe', realname='My Bot')
client.run('irc.libera.chat', tls=True, tls_verify=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment