### TODO
-- [ ] youtube api
-- [ ] raid / host shoutout
+- [x] youtube api
+- [x] raid / host shoutout
- [ ] latege (command and auto), could look through auto schedule
- [ ] basic math polish notation
-- [ ] translator (?t a replied message / database in memory of messages)
+- [x] translator
+- [ ] (?t a replied message / database in memory of messages)
- [ ] followage command
- [ ] commands in groups
- [ ] quote adder / remover / getter
- [ ] reminder (timer)
-- [ ] inch to cm
+- [x] inch to cm
- [ ] license --- opensource --- info
- [ ] streamer time
- [ ] list maker (who's up for flex)
- [ ] variable counter with cross-command functionality
- [ ] specific word in message {message.0}, {message.1}, etc.
- [ ] replied variable {reply.nick} {reply.message} {reply.message.0}
+- [ ] sub sellout bot
## Basic Commands
- [ ] int
--- /dev/null
+from aptbot.bot import Message, Commands, Bot
+import tools.smart_privmsg
+import scripts.translator
+
+PERMISSION = 99
+PREFIX = '?'
+DESCRIPTION = "Translates a message from any language (supported by google translate) into English. How to use: ?t <insert text to translate>"
+USER_COOLDOWN = 15
+GLOBAL_COOLDOWN = 5
+
+
+def main(bot: Bot, message: Message):
+ msg = ' '.join(message.value.split(' ')[1:])
+ trans = scripts.translator.translate(msg)
+ tools.smart_privmsg.send(bot, message, trans)
--- /dev/null
+from aptbot.bot import Message, Commands, Bot
+import yt_api.videos
+
+PERMISSION = 99
+PREFIX = '?'
+DESCRIPTION = "Get my newest video! Just type ?video"
+USER_COOLDOWN = 15
+GLOBAL_COOLDOWN = 15
+
+CHANNEL_ID = "UCQ7C3NUKY6TSkURdUdVoYFw"
+
+
+def main(bot: Bot, message: Message):
+ video = yt_api.videos.get_newest_video(CHANNEL_ID)
+ if video:
+ video_link = f"https://www.youtube.com/watch?v={video.video_id}"
+ msg = f"Watch my latest video \"{video.video_name}\" here -> {video_link}"
+ bot.send_privmsg(message.channel, msg)
+ else:
+ msg = f"Check out my youtube channel here -> https://www.youtube.com/channel/{CHANNEL_ID}"
-import tools.raid
-import tools.smart_privmsg
-import tools.permissions
from aptbot.bot import Bot, Message, Commands
import os
import importlib
from importlib import reload
import traceback
import ttv_api.users
+import tools.raid
+import tools.smart_privmsg
+import tools.permissions
import analyze_command
+import scripts.unit_converter
+import yt_api.videos
reload(tools.raid)
reload(tools.smart_privmsg)
reload(tools.permissions)
+reload(analyze_command)
+reload(scripts.unit_converter)
PATH = os.path.dirname(os.path.realpath(__file__))
COMMANDS_PATH = os.path.join(PATH, "commands")
conn = sqlite3.connect(os.path.join(PATH, "database.db"))
c = conn.cursor()
try:
- c.execute("""CREATE TABLE commands (
- command TEXT NOT NULL,
- prefix TEXT NOT NULL,
- permission INTEGER NOT NULL,
- description TEXT,
- user_cooldown INTEGER NOT NULL,
- global_cooldown INTEGER NOT NULL,
- last_used INTEGER NOT NULL,
- PRIMARY KEY (command)
- )""")
+ c.execute(
+ """
+ CREATE TABLE commands (
+ command TEXT NOT NULL,
+ prefix TEXT NOT NULL,
+ permission INTEGER NOT NULL,
+ description TEXT,
+ user_cooldown INTEGER NOT NULL,
+ global_cooldown INTEGER NOT NULL,
+ last_used INTEGER NOT NULL,
+ PRIMARY KEY (command)
+ )
+ """
+ )
except sqlite3.OperationalError:
print("Table commands exists")
try:
- c.execute("""CREATE TABLE users (
- user_id text NOT NULL,
- permission INTEGER NOT NULL,
- PRIMARY KEY (user_id)
- )""")
+ c.execute(
+ """
+ CREATE TABLE users (
+ user_id text NOT NULL,
+ permission INTEGER NOT NULL,
+ PRIMARY KEY (user_id)
+ )
+ """
+ )
except sqlite3.OperationalError as e:
print(f"Table users exists: {e}")
else:
(aptbot_id[0].user_id, 0))
try:
- c.execute("""CREATE TABLE cooldowns (
- user_id TEXT NOT NULL,
- command TEXT NOT NULL,
- user_cooldown INTEGER NOT NULL,
- FOREIGN KEY(user_id) REFERENCES users(user_id)
- FOREIGN KEY(command) REFERENCES commands(command)
- PRIMARY KEY (user_id, command)
- )""")
+ c.execute(
+ """
+ CREATE TABLE cooldowns (
+ user_id TEXT NOT NULL,
+ command TEXT NOT NULL,
+ user_cooldown INTEGER NOT NULL,
+ FOREIGN KEY(user_id) REFERENCES users(user_id)
+ FOREIGN KEY(command) REFERENCES commands(command)
+ PRIMARY KEY (user_id, command)
+ )
+ """
+ )
except sqlite3.OperationalError:
print("Table cooldowns exists")
try:
- c.execute("""CREATE TABLE command_values (
- command TEXT NOT NULL,
- value TEXT NOT NULL,
- FOREIGN KEY(command) REFERENCES commands(command)
- )""")
+ c.execute(
+ """
+ CREATE TABLE command_values (
+ command TEXT NOT NULL,
+ value TEXT NOT NULL,
+ FOREIGN KEY(command) REFERENCES commands(command)
+ )
+ """
+ )
except sqlite3.OperationalError:
print("Table cooldowns exists")
def main(bot: Bot, message: Message):
if message.command == Commands.PRIVMSG:
analyze_command.do_command(bot, message, modules)
+ scripts.unit_converter.send_metric(bot, message)
tools.raid.raid(bot, message)
--- /dev/null
+from deep_translator import GoogleTranslator
+
+
+def translate(text: str) -> str:
+ trans = GoogleTranslator(source="auto", target="en").translate(text)
+ return trans
--- /dev/null
+from aptbot.bot import Bot, Message, Commands
+import spacy
+import re
+import tools.smart_privmsg
+
+nlp = spacy.load("en_core_web_sm")
+
+
+def send_metric(bot: Bot, message: Message):
+ text = ""
+ ft_inch, cm = _tometric(message.value)
+ for i in range(len(cm)):
+ if cm[i] > 230:
+ text += f"{ft_inch[i][0]:.1f}ft. and {ft_inch[i][1]:.1f}in. is {cm[i] / 100:.2f}m. | "
+ elif cm[i] > 0:
+ text += f"{ft_inch[i][0]:.1f}ft. and {ft_inch[i][1]:.1f}in. is {cm[i]:.1f}cm. | "
+ if text:
+ tools.smart_privmsg.send(bot, message, text)
+
+
+def _tometric(text: str) -> tuple[list[tuple[int, int]], list[float]]:
+ ft_inch: list[tuple] = []
+ feet = 0
+ inches = 0
+ text = text.replace("-", " ")
+ text = re.sub(r"([0-9]+(\.[0-9]+)?)", r"\1 ", text)
+ text = re.sub(r"\s{2,}", r" ", text)
+ doc = nlp(text)
+ feet_was_last = False
+ next_should_be_double = False
+ found_single = False
+ for w in doc:
+ # print(w.text, w.pos_)
+ if w.pos_ in {'AUX', 'VERB', 'ADP'}:
+ if feet_was_last and not next_should_be_double:
+ ft_inch.append((feet, 0.0))
+ feet = 0
+ inches = 0
+ if w.like_num or w.pos_ == 'NUM':
+ # index_of_previous_token = w.i - 1
+ # try:
+ # prev_token = doc[index_of_previous_token]
+ # print(prev_token.lemma_)
+ # if prev_token.lemma_ != "be":
+ # continue
+ # except:
+ # pass
+ # if "'" in w.text:
+ # feet_and_inches = w.text.split("'")
+ # try:
+ # feet = float(feet_and_inches[0])
+ # inches = float(feet_and_inches[1])
+ # except:
+ # pass
+ index_of_next_token = w.i + 1
+ try:
+ next_token = doc[index_of_next_token]
+ if next_token.lemma_ in {"ft", "foot", "'"}:
+ if next_token.lemma_ == "'" and not next_should_be_double:
+ next_should_be_double = True
+ elif next_token.lemma_ == "'":
+ feet = 0
+ inches = 0
+ continue
+ if feet_was_last:
+ ft_inch.append((feet, 0.0))
+ feet = float(w.text)
+ feet_was_last = True
+ elif next_token.lemma_ in {"inch", "\""}:
+ if next_token.lemma_ == "\"" and next_should_be_double:
+ inches = float(w.text)
+ next_should_be_double = False
+ elif next_token.lemma_ == "\"":
+ inches = 0
+ elif next_should_be_double:
+ feet = 0
+ inches = float(w.text)
+ else:
+ inches = float(w.text)
+ ft_inch.append((feet, inches))
+ feet = 0
+ inches = 0
+ feet_was_last = False
+ except:
+ pass
+ if feet_was_last and not next_should_be_double:
+ ft_inch.append((feet, 0.0))
+ cm: list[float] = []
+ for unit in ft_inch:
+ cm.append((unit[0] * 12 + unit[1]) * 2.54)
+ return (ft_inch, cm)
+import ttv_api.channel
from aptbot.bot import Bot, Message, Commands
def raid(bot: Bot, message: Message):
- if message.command == Commands.USERNOTICE:
- if message.tags["msg-id"] == "raid":
- raider_name = message.tags["msg-param-displayName"]
- raider_login = message.tags["msg-param-login"]
- raider_id = message.tags["user-id"]
- raider_game = ""
- if raider_id:
- raider_channel_info = "channel info here"
- viewers = message.tags["msg-param-viewerCount"]
- viewers = f"{viewers} viewer" if viewers == "1" else f"{viewers} viewers"
- msg_reply = f"POGGERS {raider_name} has raided {message.channel} with {viewers}!!! Why don\'t you check them out at https://twitch.tv/{raider_login}"
- if raider_game:
- msg_reply += f' they were just playing {raider_game}.'
- bot.send_privmsg(message.channel, msg_reply)
+ if message.command == Commands.USERNOTICE and message.tags["msg-id"] == "raid":
+ raider_name = message.tags["msg-param-displayName"]
+ raider_login = message.tags["msg-param-login"]
+ raider_id = message.tags["user-id"]
+ raider_channel_info = ttv_api.channel.get_channels(raider_id)
+ raider_game = ""
+ if raider_channel_info:
+ raider_game = raider_channel_info[0].game_name
+ viewers = message.tags["msg-param-viewerCount"]
+ viewers = f"{viewers} viewer" if viewers == "1" else f"{viewers} viewers"
+ msg_reply = f"POGGERS {raider_name} has raided {message.channel} \
+ with {viewers}!!! Why don't you check them out at: \
+ https://twitch.tv/{raider_login}"
+ if raider_game:
+ msg_reply += f" they were just playing {raider_game}!"
+ bot.send_privmsg(message.channel, msg_reply)
--- /dev/null
+import urllib3
+from dataclasses import dataclass
+import os
+import json
+from typing import Optional
+
+URL = "https://www.googleapis.com/youtube/v3/search"
+
+API = os.getenv("YOUTUBE_API")
+CLIENT_ID = os.getenv("YOUTUBE_CLIENT_ID")
+CLIENT_SECRET = os.getenv("YOUTUBE_CLIENT_SECRET")
--- /dev/null
+from yt_api import *
+
+
+@dataclass
+class Video:
+ video_name: str
+ video_id: str
+
+
+def get_newest_video(channel_id: str) -> Optional[Video]:
+ get_video_snippets = "?part=snippet"
+ get_url = URL + get_video_snippets + \
+ f"&channelId={channel_id}&order=date&type=video" + f"&key={API}"
+
+ http = urllib3.PoolManager()
+ r = http.request(
+ "GET",
+ get_url,
+ )
+ print(f"the r.status is {r.status}")
+ if r.status != 200:
+ return None
+ data = json.loads(r.data.decode("utf-8"))["items"][0]
+ video_id = data["id"]["videoId"]
+ video_title = data["snippet"]["title"]
+
+ return Video(video_title, video_id)