2024-12-26 03:34:05 -08:00
__version__ = " 0.0.2 Funni update " + " . https://git.swee.codes/swee/MeowNex "
2024-09-10 21:47:28 -07:00
import socket
import subprocess
from time import sleep , time , ctime
2024-09-22 13:14:17 -07:00
from os import system as ossystem , path , environ , listdir , getcwd
2024-09-22 13:21:56 -07:00
import sqlite3
2024-09-22 13:14:17 -07:00
cwd = getcwd ( )
2024-09-10 21:47:28 -07:00
import re
2024-12-01 14:03:41 -08:00
from random import choice , randint as random , randrange
2024-09-10 21:47:28 -07:00
import traceback
import threading
2024-10-02 21:56:40 -07:00
from pathlib import Path
2024-12-17 16:24:56 -08:00
from urllib . parse import urlparse , parse_qs
2024-10-12 16:11:43 -07:00
from requests import get , exceptions as rex
2024-10-12 15:19:19 -07:00
from bs4 import BeautifulSoup
2024-11-20 09:48:54 -08:00
from googleapiclient . discovery import build
2024-12-28 20:31:57 -08:00
from characterai import pycai
2024-12-30 16:06:48 -08:00
import uuid
2024-12-28 20:34:12 -08:00
CAItoken = environ [ " CAItoken " ]
CAImodel = environ [ " CAIchara " ]
2024-12-28 20:31:57 -08:00
try :
cai = pycai . Client ( CAItoken )
me = cai . get_me ( )
chats = [ ]
except :
print ( traceback . format_exc ( ) )
2024-12-04 22:38:51 -08:00
run = 0
block = 0
2024-12-06 18:32:10 -08:00
parsed = 0
2024-12-28 20:31:57 -08:00
lastquery = " None yet. "
2024-12-04 22:38:51 -08:00
# Dashboard thread
2024-12-30 16:06:48 -08:00
from flask import Flask , send_file , abort as abrt , redirect as redir
2024-12-04 22:38:51 -08:00
app = Flask ( __name__ )
2024-12-30 16:06:48 -08:00
responses_ai = { } # {uuid: response}
2024-12-04 22:38:51 -08:00
@app.route ( ' / ' )
2024-12-06 18:04:14 -08:00
def index_html ( ) :
2024-12-06 18:30:35 -08:00
return send_file ( " dashboard.html " , mimetype = ' text/html ' )
2024-12-04 22:38:51 -08:00
@app.route ( ' /run.txt ' )
2024-12-06 18:04:14 -08:00
def runs ( ) :
2024-12-04 22:38:51 -08:00
return str ( run )
@app.route ( ' /block.txt ' )
2024-12-06 18:04:14 -08:00
def blocks ( ) :
2024-12-04 22:38:51 -08:00
return str ( block )
2024-12-06 18:30:35 -08:00
@app.route ( ' /link.txt ' )
2024-12-06 18:31:19 -08:00
def parses ( ) :
2024-12-06 18:30:35 -08:00
return str ( parsed )
2024-12-04 22:38:51 -08:00
@app.route ( ' /script.js ' )
2024-12-06 18:04:14 -08:00
def script_js ( ) :
2024-12-04 22:38:51 -08:00
return send_file ( " script.js " , mimetype = ' application/javascript ' )
2024-12-28 20:31:57 -08:00
@app.route ( ' /lastquery.txt ' )
def lastquery_txt ( ) :
return str ( lastquery )
2024-12-22 19:59:02 -08:00
@app.route ( ' /docs/config ' )
def config_docs ( ) :
return redir ( " https://git.swee.codes/swee/MeowNex/src/branch/main/docs/config.md " )
2024-12-30 16:06:48 -08:00
@app.route ( ' /response/<uuid> ' )
def ai_response_truncate ( uuidd ) :
if uuidd in responses_ai :
res = responses_ai [ uuidd ]
return f ' <title>AI response { uuidd } </title> \n <meta name= " viewport " content= " width=device-width, initial-scale=1.0 " > \n <link rel= " stylesheet " href= " https://swee.codes/style.css " type= " text/css " > \n <body><center><h1>AI response { uuidd } </h1><br><br> ' + f " <textarea class=code width=100% spellcheck= \" false \" autocapitalize= \" off \" autocomplete= \" off \" autocorrect= \" off \" readonly= \" true \" > { res } </textarea> "
else :
abrt ( 404 )
2024-12-06 18:00:51 -08:00
threading . Thread ( target = app . run , daemon = True , kwargs = { " port " : 2005 } ) . start ( )
2024-12-04 22:38:51 -08:00
2024-12-17 16:24:56 -08:00
# YouTube API
2024-11-20 09:48:54 -08:00
DEVELOPER_KEY = environ [ " ytapi " ]
2024-10-12 15:50:22 -07:00
headers = {
2024-12-27 01:03:15 -08:00
' User-Agent ' : ' MeowNexUS IRC ' + __version__
2024-10-12 15:50:22 -07:00
}
2024-12-17 16:24:56 -08:00
def get_yt_id ( url ) :
query = urlparse ( url )
# youtu.be already contains the ID in the path
if query . hostname == ' youtu.be ' : return query . path [ 1 : ]
if query . hostname in { ' www.youtube.com ' , ' youtube.com ' , ' music.youtube.com ' } :
# URLs that have the ID in the path instead of the query.
integrated_in_url = [ " watch " , " embed " , " v " , " shorts " ]
2024-12-17 16:34:07 -08:00
try :
# The regular /watch path, which stores the ID in the query.
if query . path == ' /watch ' : return parse_qs ( query . query ) [ ' v ' ] [ 0 ]
# Alternatively, it will get the ID in the path if the path was in the list above.
elif query . path . split ( ' / ' ) [ 1 ] in integrated_in_url : return query . path . split ( ' / ' ) [ 2 ]
except :
return None
2024-09-22 13:14:17 -07:00
class config :
def __init__ ( self ) :
2024-09-22 13:20:12 -07:00
self . conn = sqlite3 . connect ( environ [ " SBconfig " ] )
2024-09-22 13:18:15 -07:00
self . database = self . conn . cursor ( )
2024-12-28 18:27:44 -08:00
def perms ( self , mask : str ) :
2024-09-22 13:14:17 -07:00
try :
2024-12-28 18:27:44 -08:00
self . database . execute ( f " SELECT * FROM users; " )
2024-09-22 13:14:17 -07:00
output = self . database . fetchall ( )
2024-12-28 18:27:44 -08:00
for i in output :
if re . match ( i [ 0 ] . replace ( " * " , " .+ " ) , mask ) :
return i [ 1 ]
return ' '
2024-09-22 13:14:17 -07:00
except :
2024-09-22 13:47:08 -07:00
print ( traceback . format_exc ( ) )
2024-09-22 13:14:17 -07:00
return ' '
2024-10-12 14:25:36 -07:00
def chansettings ( self , chan : str ) :
try :
2024-10-12 14:28:11 -07:00
self . database . execute ( " SELECT * FROM chans WHERE chan = ?; " , [ chan ] )
2024-10-12 14:25:36 -07:00
output = self . database . fetchall ( )
2024-10-12 15:25:22 -07:00
print ( output )
2024-10-12 14:25:36 -07:00
temp = output [ 0 ] [ 1 ] . split ( " , " )
return temp if temp != [ ' ' ] else [ ]
except :
print ( traceback . format_exc ( ) )
return [ ]
def setchanconfig ( self , chan : str , flags : list ) :
try :
2024-10-12 15:26:29 -07:00
print ( self . chansettings ( chan ) )
2024-10-12 14:25:36 -07:00
if self . chansettings ( chan ) == [ ] :
print ( " [!!!] Channel doesn ' t exist in config " )
2024-10-12 15:46:27 -07:00
self . database . execute ( " INSERT INTO chans (chan, flags) values(?, ?); " , [ chan , " +config, " + " , " . join ( flags ) ] )
2024-10-12 14:53:38 -07:00
else :
self . database . execute ( " UPDATE chans SET FLAGS = ? WHERE chan = ? " , [ " , " . join ( flags ) , chan ] )
2024-10-12 14:38:58 -07:00
self . conn . commit ( )
2024-10-12 14:25:36 -07:00
except :
print ( traceback . format_exc ( ) )
return False
2024-10-12 14:50:59 -07:00
def cflagexist ( self , chan : str , flag : str ) :
return flag in self . chansettings ( chan )
2024-10-12 14:25:36 -07:00
2024-09-22 13:49:56 -07:00
2024-09-10 21:47:28 -07:00
# Code snippet from my buddy Irish
# Define a dictionary to map terminal color codes to IRC color codes
color_map = {
' \033 [30m ' : ' \x03 01 ' , # Black
' \033 [31m ' : ' \x03 05 ' , # Red
' \033 [32m ' : ' \x03 03 ' , # Green
' \033 [33m ' : ' \x03 07 ' , # Yellow
' \033 [34m ' : ' \x03 02 ' , # Blue
' \033 [35m ' : ' \x03 06 ' , # Magenta
' \033 [36m ' : ' \x03 10 ' , # Cyan
' \033 [37m ' : ' \x03 15 ' , # White
' \033 [90m ' : ' \x03 14 ' , # Bright Black (Gray)
' \033 [91m ' : ' \x03 04 ' , # Bright Red
' \033 [92m ' : ' \x03 09 ' , # Bright Green
' \033 [93m ' : ' \x03 08 ' , # Bright Yellow
' \033 [94m ' : ' \x03 12 ' , # Bright Blue
' \033 [95m ' : ' \x03 13 ' , # Bright Magenta
' \033 [96m ' : ' \x03 11 ' , # Bright Cyan
' \033 [97m ' : ' \x03 16 ' , # Bright White
' \033 [0m ' : ' \x03 ' , # Reset
}
pattern = re . compile ( r ' \ 033 \ [ \ d+(; \ d+)*m| \ 033 \ [ \ ?25[lh]| \ 033 \ [ \ ?7[lh]| \ 033 \ [ \ d+C| \ 033 \ [ \ d+A| \ 033 \ [ \ d+D| \ 033 \ [ \ d+B ' )
2024-11-11 16:46:44 -08:00
def humanbytes ( B ) :
""" Return the given bytes as a human friendly KB, MB, GB, or TB string. """
B = float ( B )
KB = float ( 1024 )
MB = float ( KB * * 2 ) # 1,048,576
GB = float ( KB * * 3 ) # 1,073,741,824
TB = float ( KB * * 4 ) # 1,099,511,627,776
2024-09-10 21:47:28 -07:00
2024-11-11 16:46:44 -08:00
if B < KB :
return ' {0} {1} ' . format ( B , ' Bytes ' if 0 == B > 1 else ' Byte ' )
elif KB < = B < MB :
return ' {0:.2f} KB ' . format ( B / KB )
elif MB < = B < GB :
return ' {0:.2f} MB ' . format ( B / MB )
elif GB < = B < TB :
return ' {0:.2f} GB ' . format ( B / GB )
elif TB < = B :
return ' {0:.2f} TB ' . format ( B / TB )
2024-12-22 19:14:44 -08:00
def rplce ( text , old , new , n ) :
parts = text . split ( old )
if len ( parts ) < = n :
return text # Not enough occurrences to replace
return old . join ( parts [ : n ] ) + new + old . join ( parts [ n : ] )
2024-09-10 21:47:28 -07:00
def replace_color_codes ( text ) :
def replacer ( match ) :
code = match . group ( 0 )
if code in color_map :
return color_map [ code ]
elif re . match ( r ' \ 033 \ [ \ d+C ' , code ) :
# Handle cursor move right (e.g., \033[30C)
spaces = int ( re . findall ( r ' \ d+ ' , code ) [ 0 ] )
return ' ' * spaces
elif re . match ( r ' \ 033 \ [ \ d+A ' , code ) or re . match ( r ' \ 033 \ [ \ d+B ' , code ) :
# Handle cursor move up (e.g., \033[17A) and down (e.g., \033[17B)
return ' '
elif re . match ( r ' \ 033 \ [ \ d+D ' , code ) :
# Handle cursor move to the start of the line (e.g., \033[9999999D)
return ' '
elif re . match ( r ' \ 033 \ [ \ ?25[lh] ' , code ) :
# Handle cursor visibility (e.g., \033[?25l or \033[?25h)
return ' '
elif re . match ( r ' \ 033 \ [ \ ?7[lh] ' , code ) :
# Handle line wrapping (e.g., \033[?7l or \033[?7h)
return ' '
else :
return ' '
# Remove all control sequences
cleaned_text = pattern . sub ( replacer , text )
# Split the text into lines and remove lines that contain control sequences or are empty
lines = cleaned_text . split ( ' \n ' )
lines = [ line for line in lines if line . strip ( ) and not re . search ( r ' \ 033 \ [m ' , line ) ]
# Join the cleaned lines back into a single string
return ' \n ' . join ( lines )
class bot_irc :
irc_socket = socket . socket ( )
def __init__ ( self ) :
self . irc_socket = socket . socket ( socket . AF_INET , socket . SOCK_STREAM )
def send_irc ( self , channel , msg ) :
2024-09-10 21:55:51 -07:00
self . irc_socket . send ( bytes ( " PRIVMSG " + channel + " : " + msg + " \n " , " UTF-8 " ) )
2024-09-10 21:47:28 -07:00
def connect_irc ( self , server , port , channel , bot_nick , bot_pass , bot_nickpass ) :
print ( " Server connection: " + server )
self . irc_socket . connect ( ( server , port ) )
self . irc_socket . send (
bytes (
2024-12-27 01:03:15 -08:00
" USER " + bot_nick + " " + bot_nick + " " + bot_nick + " :MeowNexUS, a very cool bot made by Swee :3 \n " ,
2024-09-10 21:47:28 -07:00
" UTF-8 " ,
)
)
self . irc_socket . send ( bytes ( " NICK " + bot_nick + " \n " , " UTF-8 " ) )
self . irc_socket . send (
bytes ( " PASS " + bot_nickpass + " : " + bot_pass + " \n " , " UTF-8 " )
)
for i in channel :
self . irc_socket . send ( bytes ( " JOIN " + i + " \n " , " UTF-8 " ) )
def response_irc ( self ) :
try :
r = self . irc_socket . recv ( 2040 ) . decode ( )
if r . find ( " PING " ) != - 1 :
self . irc_socket . send (
bytes ( " PONG " + r . split ( ) [ 1 ] + " \r \n " , " UTF-8 " )
)
return r
except :
return " "
def ping ( self ) :
try :
r = self . irc_socket . recv ( 2040 ) . decode ( )
if r . find ( " PING " ) != - 1 :
self . irc_socket . send (
bytes ( " PONG " + r . split ( ) [ 1 ] + " \r \n " , " UTF-8 " )
)
except :
pass
2024-11-17 15:07:44 -08:00
2024-09-10 21:47:28 -07:00
server_irc = " 127.0.0.1 " # Use 127.0.0.1 for local ZNC
2024-12-08 22:39:02 -08:00
port_irc = 5000 # NO SSL FOR YOU
2024-09-10 21:47:28 -07:00
channel_irc = [ " ##sweezero " ]
botnick_irc = environ . get ( ' SBnick ' )
botnickpass_irc = environ . get ( ' SBuser ' )
botpass_irc = environ . get ( ' SBpass ' )
2024-11-16 21:09:58 -08:00
allowedparse = [ " text/html " , " application/x-httpd-php " , " application/xhtml " , " application/xhtml+xml " ]
2024-09-10 21:47:28 -07:00
irc = bot_irc ( )
irc2 = bot_irc ( )
irc3 = bot_irc ( )
irc . connect_irc (
2024-11-09 23:58:06 -08:00
server_irc , port_irc , channel_irc , botnick_irc , botpass_irc , botnickpass_irc + " /A "
2024-09-10 21:47:28 -07:00
)
2024-09-22 13:14:17 -07:00
sbconfig = config ( )
2024-09-10 21:47:28 -07:00
threes = [ " :3 " , " :3c " , " uwu " , " owo " , " /ᐠ。ꞈ。ᐟ \\ " , " (✿◠‿◠) " ]
snacks = [ " PepperMintHTMLs " , " Dice App candies " , " SweeCrypt codes " , " Windows 11 Bloomberry flavored icecream " ]
2024-12-01 14:03:41 -08:00
baps = [ " T-T " , " Ow! " , " Beep! " ]
pats = [ " -w- " , " Meep... " , " Prr! " ]
meows_happy = [ ' Meow! ' , ' Nyaa~ ' , ' Mrow. ' , ' Prr! :3 ' , " Mrrp? " , " Mreow. " , " !woeM " , " 3: !rrP " , " ~aayN " , " Mew! " , " Moew! " ]
meows_upset = [ ' Hiss! ' , " !ssiH " , " Grrr... " ]
2024-12-06 18:44:26 -08:00
my_self = [ " MeowNexUS " , " MeowNexU5 " , " MeowN3xUS " ]
2024-12-22 19:14:44 -08:00
logs = { } # {channel: [line, line]} max 10 lines
2024-12-01 14:03:41 -08:00
happiness = 5
2024-09-10 21:47:28 -07:00
global times
times = 0
2024-12-28 20:31:57 -08:00
ai_storage = { }
2024-12-23 16:16:41 -08:00
emoticons = { " ;3 " : " I think you forgot to press shift " , " :# " : " Wait no, don ' t hold shift THAT long! " }
2024-09-10 21:47:28 -07:00
def irci2 ( ) :
irc2 . connect_irc (
2024-11-09 23:58:06 -08:00
server_irc , port_irc , channel_irc , " sweeB0t " , botpass_irc , botnickpass_irc + " /B "
2024-09-10 21:47:28 -07:00
)
while True :
irc2 . ping ( )
def irci3 ( ) :
irc3 . connect_irc (
2024-11-09 23:58:06 -08:00
server_irc , port_irc , channel_irc , " swe3Bot " , botpass_irc , botnickpass_irc + " /C "
2024-09-10 21:47:28 -07:00
)
while True :
irc3 . ping ( )
def multiline ( text , channel ) :
global times
if text . __class__ == bytes :
text = text . decode ( )
for t in text . split ( " \n " ) :
if t != " " and t != " " :
if times > 8 :
if times == 9 :
sleep ( 1 )
irc3 . send_irc ( channel , replace_color_codes ( t ) )
times + = 1
if times == 13 :
times = 0
elif times > 4 :
if times == 5 :
sleep ( 1 )
irc2 . send_irc ( channel , replace_color_codes ( t ) )
times + = 1
else :
if times == 0 :
sleep ( 1 )
irc . send_irc ( channel , replace_color_codes ( t ) )
times + = 1
2024-11-17 15:07:44 -08:00
from sys import exit
2024-11-09 23:58:06 -08:00
def restart ( ) :
irc . irc_socket . close ( )
irc2 . irc_socket . close ( )
irc3 . irc_socket . close ( )
exit ( 0 )
2024-12-06 23:07:34 -08:00
def system ( cmd , chan , rstrip = False ) :
2024-09-10 21:47:28 -07:00
try :
p = subprocess . Popen ( cmd , stdout = subprocess . PIPE , stderr = subprocess . STDOUT )
2024-12-06 23:07:34 -08:00
outpp = " "
2024-09-10 21:47:28 -07:00
for line in iter ( p . stdout . readline , b ' ' ) :
if text != " " and text != " " :
2024-12-06 23:08:54 -08:00
if not rstrip :
2024-12-06 23:07:34 -08:00
multiline ( line . rstrip ( ) , chan )
else :
2024-12-06 23:10:16 -08:00
outpp + = line . decode ( ) . rstrip ( ) + " "
2024-12-06 23:07:34 -08:00
if rstrip :
2024-12-06 23:11:51 -08:00
multiline ( outpp [ : - 1 ] , chan )
2024-09-10 21:47:28 -07:00
p . stdout . close ( )
p . wait ( )
except FileNotFoundError :
multiline ( cmd [ 0 ] + " not found " , chan )
except :
2024-12-06 23:10:56 -08:00
multiline ( traceback . format_exc ( ) , chan )
2024-11-17 15:07:44 -08:00
irl2 = threading . Thread ( target = irci2 , daemon = True )
2024-09-10 21:47:28 -07:00
irl2 . start ( )
2024-11-17 15:07:44 -08:00
irl3 = threading . Thread ( target = irci3 , daemon = True )
2024-09-10 21:47:28 -07:00
irl3 . start ( )
while True :
teext = irc . response_irc ( ) . split ( " \r \n " )
for text in teext :
if text != " " :
try :
print ( text )
except :
print ( " " )
try :
command = text . split ( " PRIVMSG " ) [ 1 ] . split ( " : " ) [ 1 : ]
command = " : " . join ( command ) . split ( " " )
channel = text . split ( " PRIVMSG " ) [ 1 ] . split ( " " ) [ 1 ]
nick = text . split ( " " ) [ 0 ] [ 1 : ] . split ( " ! " ) [ 0 ]
username = text . split ( " " ) [ 0 ] [ 1 : ] . split ( " @ " ) [ 1 ]
2024-12-28 18:27:44 -08:00
mask = text . split ( " " ) [ 0 ] [ 1 : ]
2024-09-10 21:47:28 -07:00
try :
2024-12-28 18:27:44 -08:00
perms = sbconfig . perms ( mask )
2024-09-10 21:47:28 -07:00
except :
perms = " "
print ( command )
print ( channel )
print ( nick )
print ( username )
print ( perms )
2024-12-22 19:14:44 -08:00
cont = " " . join ( command )
if not channel in logs :
2024-12-22 19:18:28 -08:00
logs [ channel ] = [ { " nick " : nick , " content " : cont } ]
2024-12-22 19:30:08 -08:00
else :
logs [ channel ] . append ( { " nick " : nick , " content " : cont } )
2024-12-22 20:37:39 -08:00
if len ( logs [ channel ] ) > 128 : logs [ channel ] = logs [ channel ] [ : : - 1 ] [ : 128 ] [ : : - 1 ]
2024-09-10 21:47:28 -07:00
#open("log-text-"+channel, "a").write(" ".join(command) + "\n")
#open("log-name-"+channel, "a").write(nick + "\n")
except :
2024-12-22 19:17:53 -08:00
print ( traceback . format_exc ( ) )
2024-12-22 19:40:05 -08:00
def replased ( expression ) :
if channel in logs :
try :
if expression . split ( " / " ) [ 0 ] . lower ( ) != " s " : raise IndexError ( )
find = expression . split ( " / " ) [ 1 ]
replace = expression . split ( " / " ) [ 2 ]
user = None
repeat = False
index = 1
try :
extraflags = expression . split ( " / " ) [ 3 : ]
for i in extraflags :
2024-12-22 19:44:20 -08:00
if i . strip ( ) == " " :
pass
elif i . lower ( ) == " g " :
2024-12-22 19:40:05 -08:00
repeat = True
elif i . strip ( ) . isdigit ( ) :
print ( f " index = { int ( i ) } " )
index = int ( i )
else :
print ( f " user = { i . lower ( ) } " )
user = i . lower ( )
except : pass
cache = None
2024-12-22 20:37:39 -08:00
for i in logs [ channel ] [ : : - 1 ] :
2024-12-22 19:40:05 -08:00
if find in i [ " content " ] and ( user == None or i [ " nick " ] . lower ( ) == user ) :
cache = i
break
if cache == None :
raise Exception ( " The specified text couldn ' t be found " )
else :
if repeat :
cache [ " content " ] = cache [ " content " ] . replace ( find , replace )
else :
cache [ " content " ] = rplce ( cache [ " content " ] , find , replace , index )
cachenick = cache [ " nick " ]
cachecontent = cache [ " content " ]
multiline ( f " [RPL] < { cachenick } > { cachecontent } " , channel )
except IndexError :
irc . send_irc ( channel , nick + " : [ERR] Sed expression might be incorrectly written! " )
except Exception as ex :
irc . send_irc ( channel , nick + " : [ERR] " + str ( ex ) )
else :
irc . send_irc ( channel , nick + " : [!!!] No logs saved in " + channel )
2024-09-10 21:47:28 -07:00
try :
#if True:
2024-12-06 18:44:26 -08:00
if " PRIVMSG " in text and not nick in my_self :
2024-09-10 21:47:28 -07:00
if " PRIVMSG " in text and command [ 0 ] [ 0 ] == " $ " :
2024-12-22 20:39:00 -08:00
logs [ channel ] = logs [ channel ] [ : - 1 ]
2024-09-10 21:47:28 -07:00
run + = 1
if command [ 0 ] == " $ping " :
if random ( 1 , 2 ) == 1 :
irc . send_irc ( channel , nick + " : Pnog " )
else :
irc . send_irc ( channel , nick + " : Pong " )
elif command [ 0 ] == " $help " :
if len ( command ) > 1 :
if " . " in " " . join ( command [ 1 : ] ) :
irc . send_irc ( channel , nick + " : Nice try " )
block + = 1
run - = 1
2024-12-08 10:48:53 -08:00
2024-09-10 21:47:28 -07:00
else :
2024-09-22 14:11:53 -07:00
try :
if path . isfile ( cwd + " /helps/ " + " " . join ( command [ 1 : ] ) ) :
output = open ( cwd + " /helps/ " + " " . join ( command [ 1 : ] ) ) . read ( )
2024-10-12 16:24:59 -07:00
multiline ( output , nick if sbconfig . cflagexist ( channel , " -multiline " ) else channel )
2024-09-22 14:11:53 -07:00
else :
irc . send_irc ( channel , " Either the command isn ' t documented yet or it doesn ' t exist lol " )
except :
multiline ( output , channel )
2024-09-10 21:47:28 -07:00
else :
2024-09-22 13:59:28 -07:00
irc . send_irc ( channel , " tip, ping, whoami, perms, version, figlet, tdfiglet, cowsay, uptime, cc, joke, botsnack. (restart, join, part, shell, config, pull.) Use ' $help (command) ' for explanation. " )
2024-11-17 15:07:44 -08:00
2024-09-10 21:47:28 -07:00
elif command [ 0 ] == " $tip " :
2024-12-06 23:07:34 -08:00
system ( [ " /usr/games/fortune " , " debian-hints " ] , channel , True )
2024-11-17 15:07:44 -08:00
2024-09-10 21:47:28 -07:00
elif command [ 0 ] == " $whoami " :
if perms != " " :
2024-12-28 18:30:58 -08:00
irc . send_irc ( channel , nick + " : " + mask + " (Your hostmask has permissions, use the ' perms ' command to see) " )
2024-09-10 21:47:28 -07:00
else :
2024-12-28 18:30:58 -08:00
irc . send_irc ( channel , nick + " : " + mask )
2024-11-17 15:07:44 -08:00
2024-11-15 18:11:52 -08:00
elif command [ 0 ] == " $welcome " :
2024-11-17 15:07:44 -08:00
name = nick if not len ( command ) > 1 else " " . join ( command [ 1 : ] )
2024-11-15 18:11:52 -08:00
if random ( 1 , 2 ) == 1 :
2024-11-17 15:10:31 -08:00
irc . send_irc ( channel , f " Heyo! Welcome to the channel, { name } " )
2024-11-15 18:11:52 -08:00
else :
2024-11-17 15:10:31 -08:00
irc . send_irc ( channel , f " Welcome, { name } " )
2024-11-17 15:07:44 -08:00
2024-09-10 21:47:28 -07:00
elif command [ 0 ] == " $perms " :
if len ( command ) == 2 :
2024-09-22 13:47:08 -07:00
if sbconfig . perms ( command [ 1 ] ) != " " :
2024-12-28 18:30:58 -08:00
irc . send_irc ( channel , nick + " : permissions of hostmask " + command [ 1 ] + " : " + sbconfig . perms ( command [ 1 ] ) )
2024-09-22 13:14:17 -07:00
else :
2024-12-28 18:30:58 -08:00
irc . send_irc ( channel , nick + " : The hostmask wildcard " + command [ 1 ] + " Doesn ' t have permissions. " )
2024-09-10 21:47:28 -07:00
else :
if perms != " " :
irc . send_irc ( channel , nick + " : " + perms )
else :
irc . send_irc ( channel , nick + " : none " )
elif command [ 0 ] == " $restart " :
if perms == " full " or " reboot " in perms . split ( " , " ) or " restart " in perms . split ( " , " ) :
irc . send_irc ( channel , nick + " : Restarting bot... " )
sleep ( 1 )
2024-11-09 23:58:06 -08:00
restart ( )
2024-09-10 21:47:28 -07:00
else :
irc . send_irc ( channel , nick + " : Permission denied. " )
block + = 1
run - = 1
2024-12-08 10:48:53 -08:00
2024-11-17 15:07:44 -08:00
2024-09-22 13:52:02 -07:00
elif command [ 0 ] == " $pull " :
2024-09-22 14:00:59 -07:00
if perms == " full " or " git " in perms . split ( " , " ) :
2024-09-22 13:52:02 -07:00
ossystem ( " git fetch " )
ossystem ( " git pull " )
irc . send_irc ( channel , nick + " : Pulled from Git, restarting bot... " )
2024-12-28 18:33:55 -08:00
restart ( )
2024-09-22 13:52:02 -07:00
else :
irc . send_irc ( channel , nick + " : Permission denied. " )
block + = 1
run - = 1
2024-12-08 10:48:53 -08:00
2024-09-10 21:47:28 -07:00
elif command [ 0 ] == " $join " :
if perms == " full " or " join " in perms . split ( " , " ) :
if len ( command ) == 2 :
irc . send_irc ( channel , nick + " : Joining " + command [ 1 ] )
irc . irc_socket . send ( bytes ( " JOIN " + command [ 1 ] + " \n " , " UTF-8 " ) )
irc2 . irc_socket . send ( bytes ( " JOIN " + command [ 1 ] + " \n " , " UTF-8 " ) )
irc3 . irc_socket . send ( bytes ( " JOIN " + command [ 1 ] + " \n " , " UTF-8 " ) )
2024-10-12 17:19:09 -07:00
multiline ( channel = command [ 1 ] , text = " A wild bot appears! ($join initiated by " + nick + " ) " )
2024-09-10 21:47:28 -07:00
else :
if len ( command ) == 1 :
irc . send_irc ( channel , nick + " : I NEED A CHANNEL NAME TO JOIN!!! " )
else :
irc . send_irc ( channel , nick + " : Y ' know this only uses one argument? JUST THE CHANNEL NAME!!! " )
else :
irc . send_irc ( channel , nick + " : Permission denied. " )
block + = 1
run - = 1
2024-12-08 10:48:53 -08:00
2024-11-17 15:07:44 -08:00
2024-09-10 21:47:28 -07:00
elif command [ 0 ] == " $part " :
if perms == " full " or " part " in perms . split ( " , " ) :
if len ( command ) == 2 :
irc . send_irc ( channel , nick + " : Parting " + command [ 1 ] )
irc . irc_socket . send ( bytes ( " PART " + command [ 1 ] + " \n " , " UTF-8 " ) )
irc2 . irc_socket . send ( bytes ( " PART " + command [ 1 ] + " \n " , " UTF-8 " ) )
irc3 . irc_socket . send ( bytes ( " PART " + command [ 1 ] + " \n " , " UTF-8 " ) )
else :
if len ( command ) == 1 :
irc . send_irc ( channel , " Bye bye! " )
sleep ( 1 )
irc . irc_socket . send ( bytes ( " PART " + channel + " \n " , " UTF-8 " ) )
irc2 . irc_socket . send ( bytes ( " PART " + channel + " \n " , " UTF-8 " ) )
irc3 . irc_socket . send ( bytes ( " PART " + channel + " \n " , " UTF-8 " ) )
else :
irc . send_irc ( channel , nick + " : Y ' know this only uses one or zero arguments? " )
else :
irc . send_irc ( channel , nick + " : Permission denied. " )
block + = 1
run - = 1
2024-12-28 20:31:57 -08:00
elif command [ 0 ] == " $ai-chat " :
try :
aiconnector = cai . connect ( )
2024-12-28 20:32:35 -08:00
chatquery = f " --Listen Up-- \n Your happiness level is { happiness } (Maximum 10), your emotion level will impact the conversation ' s tone. \n --END Listen Up-- \n --IRC recieve-- \n < { nick } > " + " " . join ( command [ 1 : ] )
2024-12-28 20:31:57 -08:00
if channel in ai_storage :
aimsg = aiconnector . send_message ( CAImodel , ai_storage [ channel ] , chatquery )
else :
2024-12-28 20:36:44 -08:00
new , answer = aiconnector . new_chat (
2024-12-28 20:31:57 -08:00
CAImodel , me . id
)
aimsg = aiconnector . send_message ( CAImodel , new . chat_id , chatquery )
ai_storage [ channel ] = new . chat_id
2024-12-30 16:06:48 -08:00
randomname = str ( uuid . uuid4 ( ) )
responses_ai [ randomname ] = aimsg . text
mtline = " "
lastquery = f " <p>Channel: { channel } </p><p>Request:</p><br><br><textarea class=code width=100% spellcheck= \" false \" autocapitalize= \" off \" autocomplete= \" off \" autocorrect= \" off \" readonly= \" true \" > { chatquery } </textarea><hr><p>Response</p><br><br><textarea class=code width=100% spellcheck= \" false \" autocapitalize= \" off \" autocomplete= \" off \" autocorrect= \" off \" readonly= \" true \" > { aimsg . text } </textarea> "
broke = False
for num , i in enumerate ( aimsg . text . split ( " \n " ) ) :
if num == 5 :
broke = True
break
elif len ( i ) > 75 :
mtline + = " \n " + i [ : 75 ] + " ... "
broke = True
else :
mtline + = " \n " + i
if broke :
mtline + = f " \n View full response: https://irc-bot.swee.codes/response/ { randomname } "
multiline ( mtline , channel )
2024-12-28 20:31:57 -08:00
except :
multiline ( " Something went wrong while connecting to Character.AI. " , channel )
2024-12-28 20:35:45 -08:00
print ( traceback . format_exc ( ) )
2024-12-28 20:31:57 -08:00
elif command [ 0 ] == " $ai-clear " :
if channel in ai_storage :
del ai_storage [ channel ]
multiline ( " Done. " , channel )
else :
multiline ( f " There is no existing AI conversation in { channel } " , channel )
2024-09-29 11:32:40 -07:00
elif command [ 0 ] == " $socket " :
if perms == " full " :
if len ( command ) > 1 :
irc . send_irc ( channel , nick + " : Sending to socket... " )
2024-09-29 11:36:59 -07:00
irc . irc_socket . send ( bytes ( " " . join ( command [ 1 : ] ) + " \n " , " UTF-8 " ) )
irc2 . irc_socket . send ( bytes ( " " . join ( command [ 1 : ] ) + " \n " , " UTF-8 " ) )
irc3 . irc_socket . send ( bytes ( " " . join ( command [ 1 : ] ) + " \n " , " UTF-8 " ) )
2024-09-29 11:32:40 -07:00
else :
irc . send_irc ( channel , nick + " : what to send to the server? " )
else :
irc . send_irc ( channel , nick + " : Permission denied. " )
block + = 1
run - = 1
2024-12-08 10:48:53 -08:00
2024-12-01 14:03:41 -08:00
2024-12-01 14:09:33 -08:00
elif command [ 0 ] == " $patpat " or command [ 0 ] == " $headpat " :
2024-12-01 14:27:42 -08:00
if len ( command ) == 2 :
2024-12-21 14:24:01 -08:00
if int ( command [ 1 ] ) < 50 :
for i in range ( 0 , int ( command [ 1 ] ) ) :
happiness + = ( 1 if happiness != 10 else 0 )
else :
happiness = 10
2024-12-01 14:27:42 -08:00
elif len ( command ) == 1 :
happiness + = ( 1 if happiness != 10 else 0 )
2024-12-23 16:12:39 -08:00
if len ( command ) != 2 or int ( command [ 1 ] ) < 50 :
2024-12-21 14:24:01 -08:00
multiline ( choice ( pats ) + " (Emotion: Upset " +
( " # " * int ( happiness ) ) +
( " - " * int ( 10 - happiness ) ) + " Happy) " ,
channel )
else :
multiline ( " Okay that ' s enough!! " + " (Emotion: Upset " +
( " # " * int ( happiness ) ) +
( " - " * int ( 10 - happiness ) ) + " Happy) " ,
channel )
2024-12-01 14:09:33 -08:00
elif command [ 0 ] == " $emotion " :
multiline ( " Emotion: Upset " +
( " # " * int ( happiness ) ) +
2024-12-01 14:10:08 -08:00
( " - " * int ( 10 - happiness ) ) + " Happy " ,
2024-12-01 14:09:33 -08:00
channel )
elif command [ 0 ] == " $bap " :
2024-12-01 14:27:42 -08:00
if len ( command ) == 2 :
2024-12-21 14:24:01 -08:00
if int ( command [ 1 ] ) < 50 :
for i in range ( 0 , int ( command [ 1 ] ) ) :
happiness - = ( 1 if happiness != 0 else 0 )
else :
happiness = 0
2024-12-01 14:27:42 -08:00
elif len ( command ) == 1 :
2024-12-01 21:18:30 -08:00
happiness - = ( 1 if happiness != 0 else 0 )
2024-12-23 16:12:39 -08:00
if len ( command ) != 2 or int ( command [ 1 ] ) < 50 :
2024-12-21 14:24:01 -08:00
multiline ( choice ( baps ) + " (Emotion: Upset " +
( " # " * int ( happiness ) ) +
( " - " * int ( 10 - happiness ) ) + " Happy) " ,
channel )
else :
multiline ( " Okay that ' s enough!! " + " (Emotion: Upset " +
( " # " * int ( happiness ) ) +
( " - " * int ( 10 - happiness ) ) + " Happy) " ,
channel )
2024-12-01 14:14:06 -08:00
elif command [ 0 ] == " $meow " :
if random ( 1 , 100 ) > ( happiness * 10 ) :
2024-12-01 14:18:36 -08:00
multiline ( choice ( meows_upset ) , channel )
2024-12-01 14:22:46 -08:00
else :
multiline ( choice ( meows_happy ) , channel )
2024-12-06 18:36:36 -08:00
elif command [ 0 ] == " $stats " :
2024-12-06 18:38:09 -08:00
multiline ( f " { nick } : { run } command(s) run, { block } refused, and { parsed } link(s) parsed, check out https://irc-bot.swee.codes " , channel )
2024-09-10 21:47:28 -07:00
elif command [ 0 ] == " $shell " :
if perms == " full " :
#or "shell" in perms.split(",")
if len ( command ) > 1 :
try :
system ( command [ 1 : ] , channel )
except Exception as ex :
multiline ( traceback . format_exc ( ) , channel )
else :
irc . send_irc ( channel , nick + " : What do you want me to F-ing run in the shell? " )
else :
irc . send_irc ( channel , nick + " : Permission denied. " )
block + = 1
run - = 1
2024-12-08 10:48:53 -08:00
2024-11-17 15:07:44 -08:00
2024-09-10 21:47:28 -07:00
elif command [ 0 ] == " $version " :
2024-12-27 01:03:15 -08:00
irc . send_irc ( channel , " This is MeowNexUS IRC " + __version__ )
2024-11-17 15:07:44 -08:00
2024-09-10 21:47:28 -07:00
elif command [ 0 ] == " $figlet " :
2024-10-12 16:22:17 -07:00
if not sbconfig . cflagexist ( channel , " -multiline " ) :
if len ( command ) > 1 :
try :
system ( [ ' figlet ' ] + command [ 1 : ] , channel )
except Exception as ex :
irc . send_irc ( channel , nick + " : " + ex . __class__ . __name__ )
else :
irc . send_irc ( channel , nick + " : What text should I enlarge? " )
2024-09-10 21:47:28 -07:00
else :
2024-10-12 16:22:17 -07:00
multiline ( " Multiline commands are disabled in this channel. " , channel )
2024-09-10 21:47:28 -07:00
elif command [ 0 ] == " $tdfiglet " :
2024-10-12 16:22:17 -07:00
if not sbconfig . cflagexist ( channel , " -multiline " ) :
if len ( command ) > 1 :
try :
system ( [ ' tdfiglet ' , ' -cm ' , " -r " ] + command [ 1 : ] , channel )
except Exception as ex :
irc . send_irc ( channel , nick + " : " + ex . __class__ . __name__ )
else :
irc . send_irc ( channel , nick + " : What text should I enlarge? " )
2024-09-10 21:47:28 -07:00
else :
2024-10-12 16:22:17 -07:00
multiline ( " Multiline commands are disabled in this channel. " , channel )
2024-09-10 21:47:28 -07:00
elif command [ 0 ] == " $cowsay " :
2024-10-12 16:22:17 -07:00
if not sbconfig . cflagexist ( channel , " -multiline " ) :
if len ( command ) > 1 :
try :
2024-11-10 00:51:01 -08:00
system ( [ ' /usr/games/cowsay ' ] + command [ 1 : ] , channel )
2024-10-12 16:22:17 -07:00
except Exception as ex :
irc . send_irc ( channel , nick + " : " + ex . __class__ . __name__ )
else :
irc . send_irc ( channel , nick + " : What should the cow say? " )
2024-09-10 21:47:28 -07:00
else :
2024-10-12 16:22:17 -07:00
multiline ( " Multiline commands are disabled in this channel. " , channel )
2024-09-10 21:47:28 -07:00
elif command [ 0 ] == " $uptime " :
try :
2024-10-10 16:36:18 -07:00
system ( [ ' uptime ' , ' -p ' ] , channel )
2024-09-10 21:47:28 -07:00
except Exception as ex :
irc . send_irc ( channel , nick + " : " + ex . __class__ . __name__ )
elif command [ 0 ] == " $joke " :
try :
system ( [ ' pyjoke ' ] + command [ 1 : ] , channel )
except Exception as ex :
multiline ( traceback . format_exc ( ) , channel )
2024-11-17 15:07:44 -08:00
2024-09-10 21:47:28 -07:00
elif command [ 0 ] == " $botsnack " :
multiline ( f " \x01 ACTION eats some { choice ( snacks ) } \x01 " , channel )
2024-11-15 21:23:45 -08:00
elif command [ 0 ] == " $hug " :
2024-11-16 16:56:00 -08:00
name = nick if not len ( command ) > 1 else " " . join ( command [ 1 : ] )
multiline ( f " \x01 ACTION gives a hug to { name } \x01 " , channel )
2024-11-15 21:23:45 -08:00
2024-09-10 21:47:28 -07:00
2024-12-06 18:44:26 -08:00
elif command [ 0 ] == " $sed " :
2024-12-22 19:16:26 -08:00
if len ( command ) == 2 :
2024-12-27 00:58:57 -08:00
replased ( " " . join ( command [ 1 : ] ) )
2024-12-06 18:44:26 -08:00
else :
2024-12-22 19:14:44 -08:00
irc . send_irc ( channel , nick + " : [???] This command takes only one argument. " )
2024-09-10 21:47:28 -07:00
2024-11-17 15:07:44 -08:00
2024-09-10 21:47:28 -07:00
elif command [ 0 ] == " $config " :
2024-10-12 14:25:36 -07:00
try :
2024-10-12 14:38:58 -07:00
if len ( command ) > 1 :
2024-10-12 14:25:36 -07:00
if perms == " full " :
2024-10-12 14:44:00 -07:00
abort = False
2024-10-12 14:38:58 -07:00
flag = sbconfig . chansettings ( channel )
2024-10-12 14:45:59 -07:00
for i in command [ 1 : ] :
2024-10-12 14:38:58 -07:00
if i == " clear " :
flag = [ " +config " ]
2024-10-12 14:44:59 -07:00
elif i [ 0 ] == " + " :
2024-10-12 14:38:58 -07:00
if " - " + i [ 1 : ] in flag :
flag [ flag . index ( " - " + i [ 1 : ] ) ] = i
2024-10-12 14:39:58 -07:00
else :
flag . append ( i )
2024-10-12 14:38:58 -07:00
elif i [ 0 ] == " - " :
if " + " + i [ 1 : ] in flag :
flag [ flag . index ( " + " + i [ 1 : ] ) ] = i
2024-10-12 14:39:58 -07:00
else :
flag . append ( i )
2024-10-12 14:38:58 -07:00
else :
2024-10-12 14:42:01 -07:00
multiline ( nick + " : flag name should begin with + or - " , channel )
2024-10-12 14:44:00 -07:00
abort = True
2024-10-12 14:38:58 -07:00
break
2024-10-12 14:44:00 -07:00
if not abort :
print ( flag )
sbconfig . setchanconfig ( channel , flag )
multiline ( nick + " : Successfuly applied configuration: " + " " . join ( flag ) , channel )
2024-09-10 21:47:28 -07:00
else :
2024-10-12 14:25:36 -07:00
irc . send_irc ( channel , nick + " : Permission denied " )
block + = 1
run - = 1
2024-12-08 10:48:53 -08:00
2024-10-12 14:25:36 -07:00
else :
multiline ( " Configuration for " + channel + " : " + " " . join ( sbconfig . chansettings ( channel ) ) , channel )
except ex :
multiline ( str ( ex ) , channel )
2024-11-17 15:07:44 -08:00
2024-09-10 21:47:28 -07:00
else :
2024-10-12 17:18:12 -07:00
if " .. " in command [ 0 ] [ : 3 ] :
2024-09-10 21:47:28 -07:00
irc . send_irc ( channel , nick + " : Nice try. " )
block + = 1
run - = 1
2024-12-08 10:48:53 -08:00
2024-09-10 21:47:28 -07:00
else :
2024-09-23 12:11:05 -07:00
if path . isfile ( " cc/ " + command [ 0 ] [ 1 : ] ) :
2024-09-10 21:47:28 -07:00
try :
2024-10-12 17:18:12 -07:00
if sbconfig . cflagexist ( channel , " -multiline " ) and " #require-multiline " in open ( " cc/ " + command [ 0 ] [ 1 : ] ) . read ( ) :
irc . send_irc ( channel , " Multiline commands are disabled in this channel. " )
else :
com = [ ' python3 ' ]
comm = command
com . append ( " cc/ " + comm [ 0 ] [ 1 : ] )
com . append ( nick )
2024-12-28 18:40:51 -08:00
com . append ( perms )
2024-10-12 17:18:12 -07:00
comm . pop ( 0 )
for i in comm :
com . append ( i )
system ( com , channel )
2024-09-10 21:47:28 -07:00
except Exception as ex :
irc . send_irc ( channel , nick + " : " + ex . __class__ . __name__ )
2024-09-23 12:11:05 -07:00
elif path . isdir ( " cc/ " + command [ 0 ] [ 1 : ] ) :
2024-10-12 17:24:53 -07:00
irc . send_irc ( channel , nick + " : Command list under cc/debug: " + " , " . join ( listdir ( " cc/ " + command [ 0 ] [ 1 : ] ) ) + " . " )
2024-09-10 21:47:28 -07:00
else :
print ( nick + " : Unrecognised command " )
2024-11-17 15:07:44 -08:00
2024-09-10 21:47:28 -07:00
elif command [ 0 ] == " :3 " :
2024-10-12 14:50:59 -07:00
if not sbconfig . cflagexist ( channel , " -colonthree " ) :
2024-10-12 17:42:37 -07:00
irc . send_irc ( channel , " :3 " )
2024-12-21 13:45:32 -08:00
elif command [ 0 ] in emoticons :
if not sbconfig . cflagexist ( channel , " -colonthree " ) :
irc . send_irc ( channel , emoticons [ command [ 0 ] ] )
2024-09-10 21:47:28 -07:00
elif " :3c " in command :
2024-12-22 23:45:06 -08:00
if sbconfig . cflagexist ( channel , " +:3c " ) or not sbconfig . cflagexist ( channel , " -colonthree " ) :
2024-12-22 19:40:05 -08:00
multiline ( choice ( threes ) , channel )
2024-12-22 19:41:04 -08:00
elif command [ 0 ] [ : 2 ] . lower ( ) == " s/ " :
2024-12-22 20:40:32 -08:00
logs [ channel ] = logs [ channel ] [ : - 1 ]
2024-12-22 19:40:28 -08:00
if sbconfig . cflagexist ( channel , " +sed " ) :
2024-12-27 00:58:57 -08:00
replased ( " " . join ( command ) )
2024-10-12 15:21:22 -07:00
# try to parse and find a link
2024-12-22 19:40:05 -08:00
2024-10-12 15:21:22 -07:00
if sbconfig . cflagexist ( channel , " +links " ) :
2024-10-12 15:24:05 -07:00
try :
for i in command :
2024-12-17 16:24:56 -08:00
parse = urlparse ( i )
if parse . scheme in [ " http " , " https " ] :
2024-10-12 16:11:43 -07:00
try :
2024-12-17 16:34:07 -08:00
if parse . hostname in [ " youtube.com " , " youtu.be " , " www.youtube.com " , " m.youtube.com " , " youtube-nocookie.com " ] and get_yt_id ( i ) != None :
try :
2024-12-17 16:24:56 -08:00
video_id = get_yt_id ( i )
youtube = build ( ' youtube ' , ' v3 ' , developerKey = DEVELOPER_KEY )
request = youtube . videos ( ) . list ( part = ' snippet,statistics ' , id = video_id )
details = request . execute ( )
title = details [ ' items ' ] [ 0 ] [ ' snippet ' ] [ ' title ' ]
2024-12-17 16:35:34 -08:00
channel_yt = details [ ' items ' ] [ 0 ] [ ' snippet ' ] [ ' channelTitle ' ]
2024-12-17 16:36:45 -08:00
views = details [ ' items ' ] [ 0 ] [ ' statistics ' ] [ ' viewCount ' ]
multiline ( f " ( { nick } ) [▶️ YouTube] { title } | Author: { channel_yt } | { views } Views " , channel )
2024-12-17 16:34:07 -08:00
except Exception as ex :
multiline ( " ( " + nick + " ) [YouTube Error, is it a valid YouTube URL?] " , channel )
print ( traceback . format_exc ( ) )
else :
2024-12-17 16:24:56 -08:00
e = get ( i , headers = headers , timeout = 10 )
header = e . headers
content_type = header . get ( ' content-type ' ) . split ( " ; " ) [ 0 ]
content_len = header . get ( ' Content-length ' )
if content_type in allowedparse :
if e . ok :
soup = BeautifulSoup ( e . text , ' html.parser ' )
multiline ( " ( " + nick + " ) " + ( " " . join ( soup . title . string . splitlines ( ) ) [ : 100 ] if soup . title != None else " [No title provided] " ) , channel )
else :
multiline ( " ( " + nick + " ) [HTTP " + str ( e . status_code ) + " ] " , channel )
else :
multiline ( " ( " + nick + " ) [ " + humanbytes ( content_len ) + " " + str ( content_type ) + " ] " , channel )
parsed + = 1
2024-10-12 16:11:43 -07:00
except rex . SSLError as ex :
2024-10-13 23:42:39 -07:00
multiline ( " ( " + nick + " ) [SSL Error: " + str ( ex . message ) + " ] " , channel )
2024-10-13 23:45:03 -07:00
except Exception as ex :
2024-12-17 16:34:07 -08:00
multiline ( " ( " + nick + " ) [Request error: " + str ( ex . message ) + " ] " , channel )
2024-10-12 15:24:05 -07:00
except :
print ( traceback . format_exc ( ) )
2024-09-10 21:47:28 -07:00
elif " JOIN " in text and " #nixsanctuary " in text :
nick = text . split ( " : " ) [ 1 ] . split ( " ! " ) [ 0 ]
2024-11-11 16:46:44 -08:00
if not " Meow " in nick :
2024-09-10 21:47:28 -07:00
irc . send_irc ( " ##hiya " , " hiya: " + nick + " has joined #nixsanctuary " )
pass
except Exception as ex :
2024-11-15 21:23:45 -08:00
print ( traceback . format_exc ( ) )