"""
)
fetched = c.fetchall()
- queue = [x[0] for x in fetched]
+ queue: list[str] = [x[0] for x in fetched]
twitch = ttv_api.users.get_users(user_ids=queue)
if not twitch:
bot.send_privmsg(
)
conn.close()
return
- queue_names = []
+ queue_users: list[ttv_api.users.User] = []
for twitch_id in queue:
for twitch_user in twitch:
if int(twitch_user.user_id) == int(twitch_id):
- queue_names.append(twitch_user.display_name)
+ queue_users.append(twitch_user)
break
else:
bot.send_privmsg(
reply=message.tags["id"],
)
- queue = queue_names[:queue_size]
- random.shuffle(queue)
- blue_team = queue[: queue_size // 2]
- red_team = queue[queue_size // 2 :]
+ queue_users: list[ttv_api.users.User] = queue_users[:queue_size]
+ random.shuffle(queue_users)
+ blue_team: list[ttv_api.users.User] = queue_users[: queue_size // 2]
+ red_team: list[ttv_api.users.User] = queue_users[queue_size // 2 :]
+
+ c.execute("UPDATE lol_queue SET team = NULL")
+ sql = f"UPDATE lol_queue SET team = 0 WHERE twitch_id IN ({(', ?' * (queue_size // 2))[2:]})"
+ c.execute(sql, tuple(user.user_id for user in blue_team))
+ sql = f"UPDATE lol_queue SET team = 1 WHERE twitch_id IN ({(', ?' * (queue_size - queue_size // 2))[2:]})"
+ c.execute(sql, tuple(user.user_id for user in red_team))
+ conn.commit()
+
+ blue_team_users: list[str] = [user.display_name for user in blue_team]
+ red_team_users: list[str] = [user.display_name for user in red_team]
bot.send_privmsg(
message.channel,
- [f"Blue team is: {blue_team}", f"Red team is: {red_team}"],
+ [f"Blue team is: {blue_team_users}", f"Red team is: {red_team_users}"],
reply=message.tags["id"],
)
tools.smart_privmsg.send(
bot,
message,
- f"These people are to play with {message.channel}: {queue_names[1:queue_size]} | and these people are waiting: {queue_names[queue_size:]}",
+ f"These people are playing with {message.channel}: {queue_names[1:queue_size]} | and these people are waiting: {queue_names[queue_size:]}",
reply=message.tags["id"],
)
+++ /dev/null
-from aptbot.bot import Message, Commands, Bot
-import os
-import logging
-import sqlite3
-
-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 = 10
-PREFIX = "\\"
-DESCRIPTION = r"Change the queue size"
-USER_COOLDOWN = 0
-GLOBAL_COOLDOWN = 0
-
-PATH = os.path.dirname(os.path.realpath(__file__))
-PATH = os.path.join(PATH, "..")
-
-
-def main(bot: Bot, message: Message):
- replied_message = message.tags.get("reply-parent-msg-body", None)
- if replied_message:
- queue_size = message.value.split(" ")[2]
- else:
- queue_size = message.value.split(" ")[1]
- try:
- queue_size = int(queue_size)
- except ValueError:
- bot.send_privmsg(
- message.channel,
- f"Please choose a number. {queue_size} is not a valid number.",
- reply=message.tags["id"],
- )
- return
-
- conn = sqlite3.connect(os.path.join(PATH, "lol_data.db"))
- c = conn.cursor()
-
- c.execute(
- """
- REPLACE INTO lol_queue_data (name, data) VALUES ('queuesize', ?)
- """,
- (queue_size,),
- )
- conn.commit()
-
- bot.send_privmsg(
- message.channel,
- f"Successfully changed queue size to {queue_size}.",
- reply=message.tags["id"],
- )
-
- conn.close()
--- /dev/null
+from aptbot.bot import Message, Commands, Bot
+import os
+import logging
+import ttv_api.users
+import sqlite3
+import tools.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 = r"Check current teams"
+USER_COOLDOWN = 30
+GLOBAL_COOLDOWN = 15
+
+PATH = os.path.dirname(os.path.realpath(__file__))
+PATH = os.path.join(PATH, "..")
+
+
+def main(bot: Bot, message: Message):
+ conn = sqlite3.connect(os.path.join(PATH, "lol_data.db"))
+ c = conn.cursor()
+
+ c.execute(
+ """
+ SELECT twitch_id, team FROM lol_queue WHERE team in (0, 1);
+ """
+ )
+ fetched = c.fetchall()
+ blue_team = []
+ red_team = []
+ for user in fetched:
+ if user[1] == 0:
+ blue_team.append(user[0])
+ elif user[1] == 1:
+ red_team.append(user[0])
+ else:
+ bot.send_privmsg(
+ message.channel,
+ f"Something VERY WEIRD occured. The user with id: {user[0]} is on team {user[1]}, which is neither blue = 0 or red = 1.",
+ reply=message.tags["id"],
+ )
+
+ users = [x[0] for x in fetched]
+ twitch = ttv_api.users.get_users(user_ids=users)
+ if not twitch:
+ bot.send_privmsg(
+ message.channel,
+ "There was an issue fetching twitch data. Sadge",
+ reply=message.tags["id"],
+ )
+ conn.close()
+ return
+ blue_team_users = []
+ red_team_users = []
+ for twitch_user in twitch:
+ if twitch_user.user_id in blue_team:
+ blue_team_users.append(twitch_user.display_name)
+ elif twitch_user.user_id in red_team:
+ red_team_users.append(twitch_user.display_name)
+ else:
+ bot.send_privmsg(
+ message.channel,
+ f"Something VERY WEIRD occured. The user with id: {twitch_user.user_id} who has the name {twitch_user.display_name} is not on a team.",
+ reply=message.tags["id"],
+ )
+
+ bot.send_privmsg(
+ message.channel,
+ [f"Blue team is: {blue_team_users}", f"Red team is: {red_team_users}"],
+ reply=message.tags["id"],
+ )
+
+ conn.close()
--- /dev/null
+from aptbot.bot import Message, Commands, Bot
+import os
+import logging
+import sqlite3
+
+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 = 10
+PREFIX = "\\"
+DESCRIPTION = r"Change the queue size"
+USER_COOLDOWN = 0
+GLOBAL_COOLDOWN = 0
+
+PATH = os.path.dirname(os.path.realpath(__file__))
+PATH = os.path.join(PATH, "..")
+
+
+def main(bot: Bot, message: Message):
+ replied_message = message.tags.get("reply-parent-msg-body", None)
+ if replied_message:
+ queue_size = message.value.split(" ")[2]
+ else:
+ queue_size = message.value.split(" ")[1]
+ try:
+ queue_size = int(queue_size)
+ except ValueError:
+ bot.send_privmsg(
+ message.channel,
+ f"Please choose a number. {queue_size} is not a valid number.",
+ reply=message.tags["id"],
+ )
+ return
+
+ conn = sqlite3.connect(os.path.join(PATH, "lol_data.db"))
+ c = conn.cursor()
+
+ c.execute(
+ """
+ REPLACE INTO lol_queue_data (name, data) VALUES ('queuesize', ?)
+ """,
+ (queue_size,),
+ )
+ conn.commit()
+
+ bot.send_privmsg(
+ message.channel,
+ f"Successfully changed queue size to {queue_size}.",
+ reply=message.tags["id"],
+ )
+
+ conn.close()
available INTEGER NOT NULL,
last_available INTEGER,
time_remaining INTEGER NOT NULL,
+ team INTEGER,
PRIMARY KEY (twitch_id)
);
"""