Compare commits
2 Commits
f449305ccd
...
f92d59dd91
Author | SHA1 | Date | |
---|---|---|---|
f92d59dd91 | |||
e3cdce4f12 |
33
bert.py
33
bert.py
@ -38,10 +38,8 @@ y = "\x038"
|
||||
r = "\x034"
|
||||
g = "\x033"
|
||||
|
||||
context = ssl.create_default_context()
|
||||
with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as sock:
|
||||
irc = context.wrap_socket(sock, server_hostname=host)
|
||||
|
||||
# global variable for the socket, see connect()
|
||||
irc = None
|
||||
|
||||
# Currency API
|
||||
def get_exchange():
|
||||
@ -71,11 +69,11 @@ def safeexit():
|
||||
|
||||
|
||||
def connect(host, port):
|
||||
global irc
|
||||
print("Connecting to "+host+":"+str(port))
|
||||
try:
|
||||
irc.connect((host, port))
|
||||
except Exception as err:
|
||||
print("Connection failed! "+str(err))
|
||||
context = ssl.create_default_context()
|
||||
with socket.create_connection((host, port)) as sock:
|
||||
irc = context.wrap_socket(sock, server_hostname=host)
|
||||
|
||||
|
||||
def sendRaw(data):
|
||||
@ -84,26 +82,17 @@ def sendRaw(data):
|
||||
|
||||
def register(nick, host):
|
||||
print("Registering User...")
|
||||
try:
|
||||
sendRaw("USER "+nick+" "+host+" "+nick+" "+nick+"\n")
|
||||
except Exception as err:
|
||||
print("Failed! "+str(err))
|
||||
|
||||
|
||||
def name(nick):
|
||||
print("Setting Nickname to "+nick)
|
||||
try:
|
||||
sendRaw("NICK "+nick+"\n")
|
||||
except Exception as err:
|
||||
print("Failed! "+str(err))
|
||||
|
||||
|
||||
def auth(nick, password):
|
||||
print("Authenticating...")
|
||||
try:
|
||||
sendRaw("PRIVMSG NickServ :IDENTIFY "+nick+" "+password+"\n")
|
||||
except Exception as err:
|
||||
print(err)
|
||||
|
||||
|
||||
def join(chan):
|
||||
@ -116,10 +105,7 @@ def join(chan):
|
||||
|
||||
def mode(nick):
|
||||
print("Setting modes +B-x")
|
||||
try:
|
||||
sendRaw("MODE "+nick+" +B-x\n")
|
||||
except Exception as err:
|
||||
print("Failed! "+str(err))
|
||||
|
||||
|
||||
def part(chan):
|
||||
@ -254,7 +240,6 @@ def ping(msg):
|
||||
|
||||
|
||||
def start(host, port, nick, password, chans):
|
||||
try:
|
||||
connect(host, port)
|
||||
sleep(2)
|
||||
register(nick, host)
|
||||
@ -268,8 +253,6 @@ def start(host, port, nick, password, chans):
|
||||
for chan in chans:
|
||||
join(chan)
|
||||
sleep(2)
|
||||
except Exception as err:
|
||||
print("FAIL: "+str(err))
|
||||
|
||||
|
||||
def command_loop():
|
||||
@ -509,7 +492,11 @@ class fefe_thread(threading.Thread):
|
||||
fefe_check()
|
||||
|
||||
def main():
|
||||
try:
|
||||
start(host, port, nick, password, set(join_chans + fefe_chans))
|
||||
except Exception as err:
|
||||
print("FAIL: "+str(err))
|
||||
sys.exit(1)
|
||||
thread_command = command_thread(1)
|
||||
#thread_fefe = fefe_thread(2)
|
||||
thread_command.start()
|
||||
|
Loading…
Reference in New Issue
Block a user