Commit 9f79a384 authored by Sven Kuhl's avatar Sven Kuhl

Sending now images

parent 170ea10b
......@@ -21,6 +21,7 @@ import time
import psutil
import logging
from abc import ABC
from random import randint
from telegram.error import NetworkError
from telegram.ext import Updater, InlineQueryHandler, CommandHandler
from telegram.ext import CallbackContext, MessageHandler, Filters
......@@ -120,12 +121,13 @@ class Bot(ABC):
self._token = token
def error_callback(self, update, context):
""" Responses with the error message. Sometimes send a meme! """
logging.error("Update '%s' caused error '%s'", update, context.error)
update.message.reply_text("Ups, something went wrong!\n'" + str(context.error)[:10] + "'")
def job_callback(context):
job = context.job
context.bot.send_message("SOMEONE", job.context)
def like_callback(update, context): # Registered with a RegexHandler with pattern (?i)i (like|dislike) (?P<thing>.*)
update.reply_text('You {} {}'.format(context.match[1], context.match.groupdict()['thing']))
try:
num = randint(0,10)
if num == 0:
file = open("Media/meme-errors.jpg", "rb")
update.reply_photo(photo=file)
except Exception:
logging.error("Cannot send error-meme!")
update.message.reply_text("Ups, something went wrong!\n'" + str(context.error)[:10] + "'")
\ No newline at end of file
......@@ -182,16 +182,17 @@ class QuizzBot(Bot):
Helper
"""
def new_user(self, user):
def new_user(self, tg_user):
""" It handles new users. """
text = "Hello "+user.first_name+", I am the QuizMaster for the Group you recently joined!\n"+\
text = "Hello "+tg_user.first_name+", I am the QuizMaster for the Group you recently joined!\n"+\
"I will just inform you about the Group: The group uses the new verions of polls of Telegram.\n"+\
"You can now create a quiz-poll by checking a option under the question and then select the right answer! :) \n"+\
"Look into the group-status for more infos or contact me by wirting: \\info \n"+\
"I also elect the king of the quizzes, the quiz master, every month. See you in the group! :*"
"Look into the group-status for more infos or contact me by wirting: /info \n"+\
"I also elect the king of the quizzes, the quiz master, every month. See you in the group! :D"
# Contact new users
self._updater.bot.send_photo()
self._updater.bot.send_message(chat_id=user.username, text=text)
file = open("Media/quiz1.jpg", "rb")
tg_user.send_photo(photo=file)
tg_user.send_message(text=text)
def get_or_add(self, tg_item, arg1=None, arg2=None):
......@@ -212,7 +213,7 @@ class QuizzBot(Bot):
result = item
# Contact new users
if model_class.__name__ == "User":
self.new_user(item)
self.new_user(tg_item)
return result
def get_model_class(self, tg_item):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment