def checkpoints(bot, update): """ Returns the cumulative house points """ # Get ID of sender ogid = update.message.chat.id points_list = pb.pb_read("Points") points_list_house = pb.pb_read("Points_H") fira = sum(points_list[1:7]) fira += points_list_house['fira'] silo = sum(points_list[7:13]) silo += points_list_house['silo'] kepa = sum(points_list[13:19]) kepa += points_list_house['kepa'] egro = sum(points_list[19:25]) egro += points_list_house['egro'] # x = "̡͙̬̻̤̺̲̦̝͙ͅs͈̱̮̠̳͈͡ e̗͔̝ ̺̝͖̟̘̺̮c͕͢ ̦̞̗͜r̖͖͍̪ ̙e̛ ̮͈̬̤t̛̖͓ͅ" # Additional line to indicate OG Number and respective points if message was sent by OG try: og = int(OG_IDS_D_rev[ogid]) og_msg = "\n\nOG {}: {}".format(og, points_list[og]) except KeyError: og_msg = "" msg = "🦁FIRA: {}\n🐥SILO: {}\n🦈KEPA: {}\n🐍EGRO: {}".format( fira, silo, kepa, egro) # msg = "🦁FIRA: {}\n🐥SILO: {}\n🦈KEPA: {}\n🐍EGRO: {}".format(x,x,x,x) msg += og_msg # Output message update.message.reply_text(msg)
def refreshdata(bot, update): """ Refresh the data in the bot """ if _checkadmin(update, 2) == False: return admins = pb.pb_read("Admins") admins = list(admins.values()) execs = pb.pb_read("Execs") execs = list(execs.values()) execs.extend(admins) OG_IDS = list(pb.pb_read("OG_IDS").values()) update.message.reply_text( "ADMINS:\n{}\n\nEXECS:\n{}\n\nOG IDS:\n{}".format( admins, execs, OG_IDS))
def addpoints(bot, update, args): """ User Input: /addpoints <OG> <Points> """ """ args[0] = <OG> args[1] = <Points> """ """ Updates points in firebase """ if _checkadmin(update, 1) == False: return og = args[0] points = args[1] if len(args) != 2 or og.isdigit() == False or points.isdigit() == False: update.message.reply_text( 'Please update points in the following format:\n/addpoints <OG> <Points>' ) else: current_points = int(pb.pb_read(og, "Points")) current_points += int(points) pb.pb_write(int(og), current_points, "Points") # Feedback to the command sender update.message.reply_text('Added {} points to OG {}!'.format( points, og)) # Feedback to the OG try: bot.send_message( chat_id=OG_IDS_D[og], text="You have been awarded {} points!".format(points)) except KeyError: update.message.reply_text('⚠️ OG IS NOT REGISTERED! ⚠️')
def registerog(bot, update, args): """ User Input: /adminaccess <password>""" """ args[0] = <password> """ """ Adds user to admin whitelist """ OG_IDS = int(args[0]) if len(args) != 1: update.message.reply_text( 'Register your OG telegram group using the following format:\n/registerog <OG #>' ) else: if OG_IDS not in list(range(1, 25)): update.message.reply_text("Please enter a OG Number from 1-24!") return if str(OG_IDS) in list(pb.pb_read("OG_IDS").keys()): update.message.reply_text("Sorry, that OG is already registered!") return # Gets the group ID user_id = update.message.chat.id # Adds the group ID to the list of OGL GROUP ID in pyrebase pb.pb_write(OG_IDS, user_id, "OG_IDS") # Feedback message update.message.reply_text("OG Registered!")
def checkallpoints(bot, update): """ Returns the Points of individual OGS to the requester """ # Check Admin Privileges if _checkadmin(update, 1) == False: return # Get points of each og from firebase points_list = pb.pb_read("Points") # Output message format msg_format = "OG {}: {}\n" # Initialise output message msg = "" # OG Counter a = 1 # Generate Response for i in range(1, 25): msg += msg_format.format(a, points_list[i]) a += 1 # Output message response update.message.reply_text(msg)
def registerog(bot, update, args): """ User Input: /registerog <OG>""" """ args[0] = <OG> """ """ Registers OG to the system """ OG_IDS = int(args[0]) # Check correct number of arguments if len(args) != 1: # Feedback if wrong number of arguments update.message.reply_text( 'Register your OG telegram group using the following format:\n/registerog <OG #>' ) else: # Check if OG is a allowed number (1-24) if OG_IDS not in list(range(1, 25)): update.message.reply_text("Please enter a OG Number from 1-24!") return # Check if OG is already registered if str(OG_IDS) in list(pb.pb_read("OG_IDS")): update.message.reply_text("Sorry, that OG is already registered!") return # Gets the group ID user_id = update.message.chat.id # Adds the group ID to the list of OGL GROUP ID in pyrebase pb.pb_write(OG_IDS, user_id, "OG_IDS") # Feedback message update.message.reply_text("OG Registered!")
def checkpoints(bot, update): """ Returns the cumulative house points """ # print(pb.pb_read("Points")) points_list = pb.pb_read("Points") print(points_list) fira = sum(points_list[1:7]) silo = sum(points_list[7:13]) kepa = sum(points_list[13:19]) egro = sum(points_list[19:25]) msg = "🦁FIRA: {}\n🐥SILO: {}\n🦈KEPA: {}\n🐍EGRO: {}\n".format( fira, silo, kepa, egro) update.message.reply_text(msg)
def checkallpoints(bot, update): if _checkadmin(update, 1) == False: return """ Returns the Points of individual OGS to the requester """ points_list = pb.pb_read("Points") msg_format = "OG {}: {}\n" msg = "" a = 1 for i in range(1, 25): msg += msg_format.format(a, points_list[i]) a += 1 update.message.reply_text(msg)
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, ReplyKeyboardMarkup from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackQueryHandler import read_write_to_firebase as pb import logging import string import time # Enable logging logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) logger = logging.getLogger(__name__) # Get Admin/Execs List admins = pb.pb_read("Admins") admins = list(admins.values()) execs = pb.pb_read("Execs") execs = list(execs.values()) execs.extend(admins) OG_IDS_D = pb.pb_read("OG_IDS") print(OG_IDS_D) OG_IDS = list(OG_IDS_D.values()) print("Admins: {}".format(admins)) print("Execs: {}".format(execs)) print("OGS: {}".format(OG_IDS)) # Telegram bot Auth Key AuthKey = "566390966:AAEPvfBKfUhb1eSct9Ty1lseKHPfzHgfQWQ" # Define a few command handlers. These usually take the two arguments bot and
def addpointsh(bot, update, args): """ User Input: /addpoints <house> <Points> """ """ args[0] = <OG> args[1] = <Points> """ """ Updates house points in firebase """ houses_d = { 'fira': [1, 2, 3, 4, 5, 6], 'silo': [7, 8, 9, 10, 11, 12], 'kepa': [13, 14, 15, 16, 17, 18], 'egro': [19, 20, 21, 22, 23, 24] } houses = ['fira', 'silo', 'kepa', 'egro'] err_msg = 'Please update points to house in the following format:\n/addpointsh <house> <Points>' # Check admin privileges if _checkadmin(update, 1) == False: return # Input Validation if len(args) != 2: update.message.reply_text(err_msg) return house = args[0] points = args[1] # Convert input to integer # Input Validation try: points = int(points) except ValueError: update.message.reply_text(err_msg) # Input Validation if len(args) != 2 or house not in houses or type(points) != int: update.message.reply_text(err_msg) return else: # Add/Minus points to firebase current_points = int(pb.pb_read(house, "Points_H")) current_points += int(points) pb.pb_write(house, current_points, "Points_H") # Message to the command sender if points >= 0: if points == 1: msg = '+{} point to {}!' else: msg = '+{} points to {}!' if points < 0: if points == -1: msg = '{} point from {}!' else: msg = '{} points from {}!' # Feedback to command sender update.message.reply_text(msg.format(points, house)) # Feedback to all OGs in House (only if added points) try: if points > 0: for i in houses_d[house]: bot.send_message( chat_id=OG_IDS_D[i], text="{} has been awarded {} points!".format( house, points)) except KeyError: update.message.reply_text('⚠️ OG IS NOT REGISTERED! ⚠️')
def addpoints(bot, update, args): """ User Input: /addpoints <OG> <Points> """ """ args[0] = <OG> args[1] = <Points> """ """ Updates points in firebase """ # Check admin privileges if _checkadmin(update, 1) == False: return # Input Validation if len(args) != 2: update.message.reply_text( 'Please update points in the following format:\n/addpoints <OG> <Points>' ) return # Label variables og = args[0] points = args[1] # Convert points input to integer # Input Validation try: points = int(points) except ValueError: update.message.reply_text( 'Please update points in the following format:\n/addpoints <OG> <Points>' ) return # Input Validation if len(args) != 2 or og.isdigit() == False or type(points) != int: update.message.reply_text( 'Please update points in the following format:\n/addpoints <OG> <Points>' ) return else: # Add points to firebase current_points = int(pb.pb_read(og, "Points")) current_points += int(points) pb.pb_write(int(og), current_points, "Points") # Feedback to the command sender # + POINTS if points >= 0: if points == 1: msg = '+{} point to OG {}!' else: msg = '+{} points to OG {}!' # - POINTS if points < 0: if points == -1: msg = '{} point from OG {}!' else: msg = '{} points from OG {}!' # Feedback message to sender update.message.reply_text(msg.format(points, og)) # Feedback to the OG (only if added points) try: if points > 0: bot.send_message( chat_id=OG_IDS_D[int(og)], text="You have been awarded {} points!".format(points)) except KeyError: # Feedback message to sender if OG is not registered. update.message.reply_text('⚠️ OG IS NOT REGISTERED! ⚠️')