def payment_success(message): time_stamp = timestamp.get_time_stamp() teacher_keys = vault.create_license_key(subscriptions[ message.json['successful_payment']['invoice_payload']]["teachers"]) dictionary_allowance = subscriptions[message.json['successful_payment'] ['invoice_payload']]["searches"] date_online = timestamp.online() data = vault.get_data() data["admin"]["payments"] = { "telegram_data": { "admin_fist_name": message.json['from']['first_name'], "admin_telegram_id": message.json['from']['id'], "telegram_chat_type": message.json['chat']['type'] }, "stripe_payment_data": { "stripe_payment_charge_id": message.json['successful_payment']['provider_payment_charge_id'], "total_mount": message.json['successful_payment']['total_amount'], "Invoice payload": message.json['successful_payment']['invoice_payload'] }, "bot_data": { "teacher_allowance": teacher_allowance, "teachers": None, "teacher_keys": teacher_keys, "channels": None, "dictionary_allowance": dictionary_allowance, "dictionary_usage": None, "date_online": date_online } } vault.dump_data(data)
def add_channel(message, online, member_count): data = vault.get_data() chat_id = str(message.chat.id) channel_title = message.chat.title user_id = message.from_user.id user_name = message.from_user.first_name if chat_id in data['channels']: return if message.chat.id == message.from_user.id: premium = True else: premium = False if message.chat.id == message.from_user.id: oed_searches = 250 else: oed_searches = 60 data['channels'][chat_id] = {} data['channels'][chat_id]['member_count'] = member_count - 1 data['channels'][chat_id]['premium'] = premium data['channels'][chat_id]['channel_title'] = channel_title data['channels'][chat_id]['joined_by_id'] = user_id data['channels'][chat_id]['joined_by'] = user_name data['channels'][chat_id]['online'] = online data['channels'][chat_id]['oed_searches'] = oed_searches data['channels'][chat_id]['zoom'] = {} data['channels'][chat_id]['vocabulary'] = {} data['channels'][chat_id]['teachers'] = {} vault.dump_data(data)
def got_payment(message): chat_id = str(message.chat.id) data = vault.get_data() check_channel_is_registered(message) if message.from_user.id == 741444566: data['channels'][chat_id]['premium'] = True vault.dump_data(data) bot.send_message(chat_id, 'This group is now upgraded.') return if message.chat.id == message.from_user.id: bot.send_message(chat_id, "❗️ You cannot upgrade our private chat ❗️") bot.send_message( chat_id, "Go to a group with your students and use the /upgrade command") elif data['channels'][chat_id]['premium']: bot.send_message(chat_id, "This group is already upgraded") else: try: key_used = str(message.text.split(" ")[1]) msg = gate_keeper.upgrade_channel(chat_id, key_used) except Exception as e: print(message, e) bot.send_message(chat_id, "You need to give me a key.") bot.send_message(chat_id, "/upgrade [key]") else: bot.send_message(chat_id, msg)
def got_payment(message): check_channel_is_registered(message) print(message.text) hide_board = types.ReplyKeyboardRemove() invoice_id = message.json["successful_payment"][ "provider_payment_charge_id"] print(message.json) data = vault.get_data() data["admin"]["payments"].append({ message.from_user.id: { "date_time": timestamp.get_time_stamp(), "invoice_id": invoice_id, "number_of_keys_bought": int(message.json["successful_payment"]["invoice_payload"]), "keys": int(message.json["successful_payment"]["invoice_payload"]) } }) vault.dump_data(data) bot.send_message(message.chat.id, "Use the /key command to generate a key")
def command_vocab(message): check_channel_is_registered(message) print(message.text) chat_id = str(message.chat.id) text = message.text data = vault.get_data() if not data['channels'][chat_id]['premium']: bot.send_message( chat_id, 'This is a premium feature only.\nUse /price to buy a premium key.' ) return # else: # bot.send_message(chat_id, "Select from one of the options below", reply_markup=keyboards.vocab_Keyboard()) try: split_text = text.split(" ", 1)[1].split(" ") except Exception as e: print(message, e) bot.send_message(chat_id, vocab.list_all(chat_id), parse_mode='HTML') else: if len(split_text) <= 1: if split_text[0] == 'add': bot.send_message( chat_id, 'You must give the name and word of the list to add.\n/vocab add shopping discount sale bargain ' ) elif split_text[0] == 'delete': bot.send_message( chat_id, 'You must give the name of the list to delete.\n/vocab delete shopping' ) elif split_text[0] in data['channels'][chat_id]['vocabulary']: bot.send_message(chat_id, vocab.list_individual(chat_id, split_text[0]), parse_mode='HTML') elif len(split_text) >= 2: if split_text[0] == 'delete': list_name = split_text[1] bot.send_message(chat_id, vocab.delete_list(chat_id, list_name)) elif split_text[0] == 'add': topic = split_text[1] words = split_text[2:] bot.send_message(chat_id, vocab.add_list(chat_id, topic, words)) elif split_text[0] in data['channels'][chat_id]['vocabulary']: try: words = split_text[1:] bot.send_message( chat_id, vocab.add_list(chat_id, split_text[0], words)) except Exception as e: print(message, e) bot.send_message( chat_id, 'An error occured. Please try again later.')
def update_data(chat_id): data = vault.get_data() data['channels'][chat_id]['oed_searches'] -= 1 data['admin']['stats']['oed_searches'] += 1 if data['channels'][chat_id]['oed_searches'] <= 10: bot.send_message( chat_id, f"You have {data['channels'][chat_id]['oed_searches']} dictionary definitions remaining" ) vault.dump_data(data)
def check_oed_searches(chat_id): data = vault.get_data() if data['channels'][chat_id]['oed_searches'] >= 1: return True if data['channels'][chat_id]['oed_searches'] == 0: bot.send_message( chat_id, f"You don't have any more dictionary searches remaining", parse_mode="HTML") return False
def upgrade_channel(chat_id, key_used): data = vault.get_data() if key_used in data['admin']['keys_outstanding']: data['channels'][chat_id]['premium'] = True data['channels'][chat_id]['oed_searches'] = 250 data['channels'][chat_id]['key_used'] = key_used data['admin']["keys_outstanding"].remove(key_used) vault.dump_data(data) return ("You are now upgraded") else: return ("That key is invalid")
def command_zoom(message=None, reply=None, edit_message_id=None): '''Handles the /zoom commands and requests the appropriate action from the zoom.py module. ''' check_channel_is_registered(message) print(message.text) data = vault.get_data() user_id = str(message.from_user.id) chat_id = str(message.chat.id) if not data['channels'][chat_id]['premium']: bot.send_message( chat_id, 'This is a premium feature only.\nUse /price to buy a premium key.' ) return # NOTE: use this when implementing next feature for /zoom # bot.send_message(chat_id, f'<b>Zoom</b>\n{zoom.get_group_links(chat_id)}', parse_mode='HTML', reply_markup=keyboards.zoom_Keyboard()) def send_error_message(): bot.send_message(chat_id, 'You have made a mistake. Use /help.') args = message.text.split(" ")[ 1:] # remove the command and just get the body of the message (args) if len(args) <= 0: bot.send_message(chat_id, zoom.get_group_links(chat_id)) elif len(args) <= 1: if args[0].lower() in data['channels'][chat_id]['zoom']: bot.send_message(chat_id, zoom.get_teacher_link(chat_id, args[0].lower())) else: send_error_message() elif len(args) <= 2: if args[0].lower() == 'delete': bot.send_message(chat_id, zoom.delete_link(chat_id, args[1].lower())) else: send_error_message() elif len(args) <= 3: if args[0].lower() == 'add': bot.send_message(chat_id, zoom.add_link(chat_id, args[1].lower(), args[2])) else: send_error_message()
def secretary(command): data = vault.get_data() return_message = None if command == "list": return_message = "key - Generate a premium key\nstats - show statistics for all bots" elif command == "key": return_message = key = vault.create_license_key() elif command == 'stats': active_channels = len(data['channels']) member_count = 0 for channel in data['channels']: member_count += data['channels'][channel]['member_count'] oed_searches = data['admin']['stats']['oed_searches'] return f'There are <b>{active_channels}</b> active channels with <b>{member_count}</b> total members .\nThere has been <b>{oed_searches}</b> searches of the OED.' else: return_message = "Invalid command!" return return_message
def command_keys(message): check_channel_is_registered(message) print(message.text) user_id = str(message.from_user.id) data = vault.get_data() if len(data["admin"]["payments"]) >= 1: for buyers in data["admin"]["payments"]: if user_id in buyers: if buyers[user_id]["keys"] >= 1: buyers[user_id]["keys"] -= 1 vault.dump_data(data) bot.reply_to(message, vault.create_license_key()) else: bot.send_message( message.chat.id, "You have no more keys left.\n\nUse /pay to get more.") else: bot.send_message(message.chat.id, "You have not purchased any keys.") else: bot.send_message(message.chat.id, "You have not purchased any keys.")
def command_stats(message): # NOTE: Can change this to change 'x search/searches' depending on the number chat_id = str(message.chat.id) data = vault.get_data() member_count = str(data['channels'][chat_id]['member_count']) oed_searches = str(data['channels'][chat_id]['oed_searches']) vocab_lists = str(len(data['channels'][chat_id]['vocabulary'])) zoom_links = str(len(data['channels'][chat_id]['zoom'])) if data['channels'][chat_id]['premium']: premium = 'Yes.' else: premium = 'No.' bot.send_message(chat_id, f'''<b>Statistics</b> This group has {member_count} members. You have {oed_searches} dictionary searches left for this month. There are {vocab_lists} vocabulary lists. There are {zoom_links} Zoom links. Are you a premium member? {premium}''', parse_mode='HTML')
import json from utils import vault data = vault.get_data() def zoom_exists(chat_id): if bool(data['channels'][str(chat_id)]['zoom']): return True else: return False def add_link(chat_id, name, link): data['channels'][chat_id]['zoom'][name] = link vault.dump_data(data) return f'{name}\'s zoom link has been added' def delete_link(chat_id, name): if zoom_exists(chat_id): if name in data['channels'][chat_id]['zoom']: del data['channels'][chat_id]['zoom'][name] vault.dump_data(data) return f'{name}\'s zoom link has been deleted' else: return f'There is no record of {name} in the database' def get_group_links(chat_id): if zoom_exists(chat_id):
def remove_channel(chat_id): data = vault.get_data() del data['channels'][str(chat_id)] vault.dump_data(data)
def check_channel_is_registered(message): data = vault.get_data() if not str(message.chat.id) in data['channels']: gate_keeper.add_channel(message, timestamp.online(), bot.get_chat_members_count(message.chat.id))