Compare commits
2 Commits
167389067d
...
3158583f65
Author | SHA1 | Date | |
---|---|---|---|
|
3158583f65 | ||
|
6458f19226 |
@ -44,43 +44,23 @@ class YtService(_Service):
|
|||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
self._ydl_config = {
|
self._ydl_config = {
|
||||||
"format": "bestaudio/best",
|
"skip_download": True,
|
||||||
"outtmpl": "%(title)s.%(ext)s",
|
"format": "m4a/bestaudio/best[protocol!=m3u8_native]/best",
|
||||||
"socket_timeout": 5,
|
"socket_timeout": 5,
|
||||||
"logger": logging.getLogger("root"),
|
"logger": logging.getLogger("root"),
|
||||||
"cookiefile": "/home/ttbot/data/cookies.txt",
|
"cookiefile": "/home/ttbot/data/cookies.txt"
|
||||||
"postprocessors": [
|
|
||||||
{
|
|
||||||
"key": "FFmpegExtractAudio",
|
|
||||||
"preferredcodec": "mp3",
|
|
||||||
"preferredquality": "192",
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"postprocessor_args": [
|
|
||||||
"-ar", "44100"
|
|
||||||
],
|
|
||||||
"prefer_ffmpeg": True,
|
|
||||||
"keepvideo": False,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def download(self, track: Track, file_path: str) -> None:
|
def download(self, track: Track, file_path: str) -> None:
|
||||||
try:
|
try:
|
||||||
info = track.extra_info
|
info = track.extra_info
|
||||||
if not info:
|
if not info:
|
||||||
# fallback ke parent class kalo gak ada info
|
|
||||||
super().download(track, file_path)
|
super().download(track, file_path)
|
||||||
return
|
return
|
||||||
|
|
||||||
ydl_opts = self._ydl_config.copy()
|
with YoutubeDL(self._ydl_config) as ydl:
|
||||||
ydl_opts["outtmpl"] = file_path.rsplit(".", 1)[0] + ".mp3"
|
dl = get_suitable_downloader(info)(ydl, self._ydl_config)
|
||||||
|
dl.download(file_path, info)
|
||||||
with YoutubeDL(ydl_opts) as ydl:
|
|
||||||
# Download langsung pakai URL dari info
|
|
||||||
url = info.get("webpage_url")
|
|
||||||
if not url:
|
|
||||||
raise errors.ServiceError("Missing webpage_url in track info")
|
|
||||||
ydl.download([url])
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Download error: {str(e)}", exc_info=True)
|
logging.error(f"Download error: {str(e)}", exc_info=True)
|
||||||
raise errors.ServiceError("Download failed")
|
raise errors.ServiceError("Download failed")
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
This change log is written to find out the changes that have been made by Pandora, and the source code still refers to TTMediaBot.
|
This change log is written to find out the changes that have been made by Pandora, and the source code still refers to TTMediaBot.
|
||||||
5/5/2025
|
5/5/2025
|
||||||
Change the download from m4a to mp3, if it's work.
|
|
||||||
Added new command: e, to add either link or new song to the extended track. if nothing is playing, it plays the track directly.
|
Added new command: e, to add either link or new song to the extended track. if nothing is playing, it plays the track directly.
|
||||||
Fix user rights to upload file, hopefully...
|
Fix user rights to upload file, hopefully...
|
||||||
|
|
||||||
|
69
dd.py
Normal file
69
dd.py
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||||
|
from bot.TeamTalk import TeamTalk, Event, EventType, MessageType
|
||||||
|
|
||||||
|
|
||||||
|
# Load the watchlist from a file (watchlist.txt)
|
||||||
|
def load_watchlist():
|
||||||
|
"""Load the watchlist of prohibited words."""
|
||||||
|
watchlist = []
|
||||||
|
try:
|
||||||
|
with open("watchlist.txt", "r") as f:
|
||||||
|
watchlist = [line.strip().lower() for line in f.readlines()]
|
||||||
|
except FileNotFoundError:
|
||||||
|
logging.error("Watchlist file not found. Please create 'watchlist.txt'.")
|
||||||
|
return watchlist
|
||||||
|
|
||||||
|
|
||||||
|
# Check if the user's message contains any prohibited words
|
||||||
|
def contains_prohibited_word(message: str, watchlist: list) -> bool:
|
||||||
|
"""Check if a message contains any prohibited words from the watchlist."""
|
||||||
|
for word in watchlist:
|
||||||
|
if word in message.lower():
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
# Kick the user and broadcast the reason
|
||||||
|
def kick_user_and_broadcast(ttclient: TeamTalk, user_name: str) -> None:
|
||||||
|
"""Kick the user and broadcast a message about the kick."""
|
||||||
|
ttclient.kick_user(user_name)
|
||||||
|
broadcast_message = f"{user_name} has been kicked for using prohibited language."
|
||||||
|
ttclient.broadcast_message(broadcast_message)
|
||||||
|
logging.info(f"Kicked user: {user_name} for prohibited message.")
|
||||||
|
|
||||||
|
|
||||||
|
# Event handler for a user text message
|
||||||
|
def on_user_text_message(event: Event, ttclient: TeamTalk):
|
||||||
|
"""Handle the event when a user sends a text message."""
|
||||||
|
watchlist = load_watchlist()
|
||||||
|
message = event.message.text
|
||||||
|
user_name = event.message.sender.name
|
||||||
|
|
||||||
|
# Check if the message contains a prohibited word
|
||||||
|
if contains_prohibited_word(message, watchlist):
|
||||||
|
logging.info(f"User {user_name} used a prohibited word. Kicking user...")
|
||||||
|
kick_user_and_broadcast(ttclient, user_name)
|
||||||
|
else:
|
||||||
|
logging.info(f"User {user_name}'s message: '{message}' is clean.")
|
||||||
|
|
||||||
|
|
||||||
|
# Map event types to their respective handler functions
|
||||||
|
event_handlers = {
|
||||||
|
EventType.USER_TEXT_MESSAGE: on_user_text_message,
|
||||||
|
# You can add more event handlers here for different event types.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def run_event_handler(event: Event, ttclient: TeamTalk):
|
||||||
|
"""Run the appropriate event handler based on the event type."""
|
||||||
|
try:
|
||||||
|
event_handler = event_handlers.get(event.event_type)
|
||||||
|
if event_handler:
|
||||||
|
event_handler(event, ttclient)
|
||||||
|
else:
|
||||||
|
logging.info(f"No handler for event type: {event.event_type.name}")
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"Error in event handling: {e}")
|
4
watchlist.txt
Normal file
4
watchlist.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
anjing
|
||||||
|
stupid
|
||||||
|
idiot
|
||||||
|
fuck
|
Loading…
x
Reference in New Issue
Block a user