From eac9182b54e6d6025d1ced81db8210c177bf4a6a Mon Sep 17 00:00:00 2001 From: Georgios Atheridis Date: Fri, 6 May 2022 12:46:25 +0000 Subject: [PATCH] added opgg command --- skgyorugo/commands/addaccount.py | 4 +- skgyorugo/commands/opgg.py | 64 ++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 skgyorugo/commands/opgg.py diff --git a/skgyorugo/commands/addaccount.py b/skgyorugo/commands/addaccount.py index 7ce1c3a..b6a921a 100644 --- a/skgyorugo/commands/addaccount.py +++ b/skgyorugo/commands/addaccount.py @@ -33,11 +33,11 @@ def main(bot: Bot, message: Message): twitch_name = twitch_name.strip() summoner = lol_api.summoner_v4.get_summoner_from_name(summoner_name) twitch = ttv_api.users.get_users(user_logins=[twitch_name]) - if summoner is None: + if not summoner: logger.warning(f"Account {summoner_name} wasn't able to be added") bot.send_privmsg(message.channel, f"Error, unable to add summoner: {summoner_name}") return - if twitch is None: + if not twitch: logger.warning(f"Unable to use twitch account {twitch_name}") bot.send_privmsg(message.channel, f"Error, unable to use twitch account: {twitch_name}") return diff --git a/skgyorugo/commands/opgg.py b/skgyorugo/commands/opgg.py new file mode 100644 index 0000000..7820bd8 --- /dev/null +++ b/skgyorugo/commands/opgg.py @@ -0,0 +1,64 @@ +from aptbot.bot import Message, Commands, Bot +import sqlite3 +import os +import logging +from lol_api import spectator_v4 +from lol_api import summoner_v4 +import ttv_api.users +from tools import smart_privmsg + +logger = logging.getLogger(__name__) +logger.setLevel(logging.DEBUG) + +formatter = logging.Formatter("[%(levelname)s] %(asctime)s: %(name)s; %(message)s") + +file_handler = logging.FileHandler('/var/log/aptbot/logs.log') +file_handler.setFormatter(formatter) + +logger.handlers = [] +logger.addHandler(file_handler) + + +PERMISSION = 99 +PREFIX = '?' +DESCRIPTION = "Figures out which LoL Account {channel} is playing on" +USER_COOLDOWN = 5 +GLOBAL_COOLDOWN = 0 + + +PATH = os.path.dirname(os.path.realpath(__file__)) +PATH = os.path.join(PATH, "..") + +def main(bot: Bot, message: Message): + streamer_data = ttv_api.users.get_users(user_logins=[message.channel]) + if not streamer_data: + logger.warning(f"There was an issue getting streamer data for {message.channel}") + smart_privmsg.send(bot, message, "Couldn't retrieve data", reply=message.tags["id"]) + return + twitch_id = int(streamer_data[0].user_id) + db_name_database = "lol_data.db" + conn = sqlite3.connect(os.path.join(PATH, db_name_database)) + c = conn.cursor() + + c.execute( + """ + SELECT summoner_id, puuid FROM accounts WHERE twitch_id = ?; + """, + (twitch_id,) + ) + fetched = c.fetchall() + + summoner_names = [] + for summoners in fetched: + info = spectator_v4.get_spectator_info_from_summoner_id(summoners[0]) + summoner = summoner_v4.get_summoner_from_puuid(summoners[1]) + if summoner: + summoner_names.append(summoner.name) + if info: + break + else: + smart_privmsg.send(bot, message, f"{{channel}} is currently not in game.", reply=message.tags["id"]) + smart_privmsg.send(bot, message, f"These are all of his summoners: {summoner_names}", reply=message.tags["id"]) + return + + smart_privmsg.send(bot, message, f"{{channel}} is currently playing a game on: {summoner_names[-1]}", reply=message.tags["id"]) -- 2.30.2