import scripts.chatting
import scripts.chat
import scripts.crylaugh
+import scripts.clean_queue
+import scripts.discord_start_stream
import database_manager
import analyze_auto_message
import time
reload(scripts.chatting)
reload(scripts.chat)
reload(scripts.crylaugh)
+reload(scripts.clean_queue)
+reload(scripts.discord_start_stream)
reload(database_manager)
reload(analyze_auto_message)
i += wait
started = tools.smart_start_stream_time.update_start_stream_timestamp()
if started == "START":
+ scripts.clean_queue.clean_queue()
+ scripts.discord_start_stream.announce()
bot.send_privmsg(
message.channel, "/announce Stream has started, you can now use ?join"
)
elif started == "END":
+ scripts.clean_queue.clean_queue()
bot.send_privmsg(message.channel, "Stream has ended")
if i >= 30:
analyze_auto_message.do_auto_message(bot, message, auto_message_modules)
--- /dev/null
+import os
+import requests
+import logging
+import datetime
+import ttv_api.users
+import ttv_api.channel
+
+logger = logging.getLogger(__name__)
+
+STREAMER_PATH = os.path.abspath(os.path.join(__file__, "../.."))
+logger.debug(f"STREAMER_PATH set to: {STREAMER_PATH}")
+SCRIPTS_PATH = os.path.dirname(os.path.realpath(__file__))
+logger.debug(f"TOOLS_PATH set to: {SCRIPTS_PATH}")
+PATH = os.path.join(SCRIPTS_PATH, "..")
+logger.debug(f"PATH set to: {PATH}")
+
+STREAMER_LOGIN = os.path.split(STREAMER_PATH)[1]
+logger.debug(f"streamer_login set to: {STREAMER_LOGIN}")
+
+
+DISCORD_API = os.getenv("DISCORD_API")
+
+PEKS_CHANNEL_ID = 1048026874145681508
+
+def announce():
+ user = ttv_api.users.get_users(user_logins=[STREAMER_LOGIN])
+ if not user:
+ return
+ user = user[0]
+
+ channel = ttv_api.channel.get_channels(user.user_id)
+ if not channel:
+ return
+ channel = channel[0]
+
+ message = {
+ "content": "@everyone Peks is alive!!",
+ "embeds": [
+ {
+ "title": channel.title,
+ "description": user.description,
+ "url": f"https://twitch.tv/{STREAMER_LOGIN}",
+ "color": 13612884,
+ "author": {
+ "name": "Peks is now live!",
+ "url": f"https://twitch.tv/{STREAMER_LOGIN}",
+ "icon_url": user.profile_image_url,
+ },
+ "footer": {
+ "text": "rugo is amazing"
+ },
+ "timestamp": datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None).isoformat() + 'Z',
+ "thumbnail": {
+ "url": user.profile_image_url
+ }
+ }
+ ],
+ }
+
+ try:
+ response = requests.post(
+ f"https://discord.com/api/v10/channels/{PEKS_CHANNEL_ID}/messages",
+ headers={
+ "Authorization": f"Bot {DISCORD_API}",
+ "Content-Type": "application/json",
+ },
+ json=message,
+ )
+ except Exception as e:
+ logger.exception(e)
+ return
+ if response.status_code != 200:
+ logger.error(response.json)
MAX_OFF_STREAM_MARGIN = 60 * 60
-def end_stream():
- logger.info(f"{STREAMER_LOGIN} has ended their stream")
- clean_queue.clean_queue()
-
-
-def start_stream():
- logger.info(f"{STREAMER_LOGIN} has started their stream")
- clean_queue.clean_queue()
-
-
def start_stream_timestamp() -> Optional[int]:
conn = sqlite3.connect(os.path.join(PATH, "database.db"))
c = conn.cursor()
conn.commit()
conn.close()
# TODO add hook, streamer ended stream
- end_stream()
+ logger.info(f"{STREAMER_LOGIN} has ended their stream")
return "END"
if not fetched:
)
conn.commit()
conn.close()
- start_stream()
+ logger.info(f"{STREAMER_LOGIN} has started their stream")
return "START"
start_stream_ts, last_checked = fetched