add new version of bot to raspi \o/

This commit is contained in:
Horscchtey 2021-01-21 00:42:01 +00:00
commit d51641ee36
7 changed files with 584 additions and 0 deletions

85
bot.py Normal file
View file

@ -0,0 +1,85 @@
from telegram.ext import Updater
from telegram.ext import CommandHandler
from telegram.ext import MessageHandler
from telegram.ext import Filters
from telegram import InlineQueryResultArticle, InputTextMessageContent
import random
import logging
import sqlite3 as sql
# updater
updater = Updater(token='935673062:AAH4By1EMqAUaD9wgnV3lZQRRBX6e5Lve6g', use_context=True)
# sqlite database
connection = sql.connect("/home/horscchtey/bots/boddle/src/v2/boddle.db", check_same_thread=False)
cursor = connection.cursor()
dispatcher = updater.dispatcher
# enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
########### routinen ##########
def start(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text="I am your new source of bad jokes")
def kaffee(update, context):
cursor.execute("select distinct l.content from line l, brain b, tag t where l.id = b.line_id and t.id = b.tag_id and t.id = 8 ORDER BY RANDOM() LIMIT 1")
selection = []
result = cursor.fetchall()
for r in result:
selection.append(r[0])
context.bot.send_message(chat_id=update.effective_chat.id, text=str(selection[0]))
def radschlag(update, context):
cursor.execute("select distinct l.content from line l, brain b, tag t where l.id = b.line_id and t.id = b.tag_id and t.id = 3 ORDER BY RANDOM() LIMIT 1")
selection = []
result = cursor.fetchall()
for r in result:
selection.append(r[0])
context.bot.send_message(chat_id=update.effective_chat.id, text=str(selection[0]))
def flirt(update, context):
cursor.execute("select distinct l.content from line l, brain b, tag t where l.id = b.line_id and t.id = b.tag_id and t.id = 1 ORDER BY RANDOM() LIMIT 1")
selection = []
result = cursor.fetchall()
for r in result:
selection.append(r[0])
context.bot.send_message(chat_id=update.effective_chat.id, text=str(selection[0]))
def jokes(update, context):
cursor.execute("select distinct l.content from line l, brain b, tag t where l.id = b.line_id and t.id = b.tag_id and t.id = 4 ORDER BY RANDOM() LIMIT 1")
selection = []
result = cursor.fetchall()
for r in result:
selection.append(r[0])
context.bot.send_message(chat_id=update.effective_chat.id, text=str(selection[0]))
def unknown(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text="Sorry, I didn't understand that command.")
#inline
start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)
flirt_handler = CommandHandler('flirt', flirt)
dispatcher.add_handler(flirt_handler)
radschlag_handler = CommandHandler('radschlag', radschlag)
dispatcher.add_handler(radschlag_handler)
kaffee_handler = CommandHandler('kaffee', kaffee)
dispatcher.add_handler(kaffee_handler)
coffee_handler = CommandHandler('coffee', kaffee)
dispatcher.add_handler(coffee_handler)
jokes_handler = CommandHandler('jokes', jokes)
dispatcher.add_handler(jokes_handler)
unknown_handler = MessageHandler(Filters.command, unknown)
dispatcher.add_handler(unknown_handler)
updater.start_polling()