Compare commits
20 Commits
1259db8212
...
master
Author | SHA1 | Date | |
---|---|---|---|
97a315d2d1 | |||
b29cf737a7 | |||
51a37c4562 | |||
34a3f06d91 | |||
f92d59dd91 | |||
e3cdce4f12 | |||
f449305ccd | |||
1b252ca2c7 | |||
9aee38bc50 | |||
e709a2ade1 | |||
359407187e | |||
90fc695794 | |||
0038eecfbc | |||
7eddd9b9d7 | |||
3c49d4ecd1 | |||
5cbcb2e6f2 | |||
c92c8b368f | |||
2e71e2d6db | |||
9de4990d69 | |||
ef88dad4a8 |
107
bert.py
107
bert.py
@ -38,10 +38,8 @@ y = "\x038"
|
||||
r = "\x034"
|
||||
g = "\x033"
|
||||
|
||||
context = ssl.create_default_context()
|
||||
with socket.socket(socket.AF_INET, 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! "+err)
|
||||
context = ssl.create_default_context()
|
||||
with socket.create_connection((host, port), timeout=180) 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! "+err)
|
||||
sendRaw("USER "+nick+" "+host+" "+nick+" "+nick+"\n")
|
||||
|
||||
|
||||
def name(nick):
|
||||
print("Setting Nickname to "+nick)
|
||||
try:
|
||||
sendRaw("NICK "+nick+"\n")
|
||||
except Exception as err:
|
||||
print("Failed! "+err)
|
||||
sendRaw("NICK "+nick+"\n")
|
||||
|
||||
|
||||
def auth(nick, password):
|
||||
print("Authenticating...")
|
||||
try:
|
||||
sendRaw("PRIVMSG NickServ :IDENTIFY "+nick+" "+password+"\n")
|
||||
except Exception as err:
|
||||
print(err)
|
||||
sendRaw("PRIVMSG NickServ :IDENTIFY "+nick+" "+password+"\n")
|
||||
|
||||
|
||||
def join(chan):
|
||||
@ -111,15 +100,12 @@ def join(chan):
|
||||
try:
|
||||
sendRaw("JOIN "+chan+"\n")
|
||||
except Exception as err:
|
||||
print("Failed! "+err)
|
||||
print("Failed! "+str(err))
|
||||
|
||||
|
||||
def mode(nick):
|
||||
print("Setting modes +B-x")
|
||||
try:
|
||||
sendRaw("MODE "+nick+" +B-x\n")
|
||||
except Exception as err:
|
||||
print("Failed! "+err)
|
||||
sendRaw("MODE "+nick+" +B-x\n")
|
||||
|
||||
|
||||
def part(chan):
|
||||
@ -135,7 +121,7 @@ def say(chan, msg):
|
||||
sendRaw("PRIVMSG "+chan+" :"+msg+"\n")
|
||||
print("OK")
|
||||
except Exception as err:
|
||||
print("Error: "+err)
|
||||
print("Error: "+str(err))
|
||||
|
||||
|
||||
def raw(msg):
|
||||
@ -150,11 +136,18 @@ def me(chan, msg):
|
||||
try:
|
||||
sendRaw("PRIVMSG "+chan+" :\u0001ACTION "+msg+"\u0001\n")
|
||||
except Exception as err:
|
||||
print("Error: "+err)
|
||||
print("Error: "+str(err))
|
||||
|
||||
|
||||
def getData():
|
||||
raw = irc.recv(4096)
|
||||
try:
|
||||
raw = irc.recv(4096)
|
||||
except TimeoutError:
|
||||
print("Connection timed out!")
|
||||
sys.exit(0)
|
||||
if not raw:
|
||||
print("Connection lost!")
|
||||
sys.exit(0)
|
||||
try:
|
||||
data = raw.decode("UTF-8")
|
||||
except:
|
||||
@ -172,8 +165,8 @@ def getMessage():
|
||||
|
||||
|
||||
def getRocket():
|
||||
rocket, mission, status, delta = launch.next_launch()
|
||||
rstring = "%sNext rocket: %s%s %s| %s%s %s| %sStatus: %s %s| %s%s" % (b, y, rocket, b, y, mission, b, y, status, b, y, delta)
|
||||
rocket, mission, delta = launch.next_launch()
|
||||
rstring = "%sNext rocket: %s%s %s| %s%s %s| %s%s" % (b, y, rocket, b, y, mission, b, y, delta)
|
||||
return rstring
|
||||
|
||||
|
||||
@ -187,7 +180,7 @@ def is_registered(username):
|
||||
try:
|
||||
sendRaw("WHOIS "+str(username)+"\n")
|
||||
user_info = getMessage()
|
||||
regex = r"330 "+str(re.escape(nick))+" "+str(re.escape(username))+" \S+ :is logged in as"
|
||||
regex = rf"330 {str(re.escape(nick))} {str(re.escape(username))} \S+ :is logged in as"
|
||||
matches = re.finditer(regex, user_info, re.MULTILINE)
|
||||
for match in matches:
|
||||
acc_name = match.group(0).split()[3]
|
||||
@ -254,22 +247,19 @@ def ping(msg):
|
||||
|
||||
|
||||
def start(host, port, nick, password, chans):
|
||||
try:
|
||||
connect(host, port)
|
||||
sleep(2)
|
||||
register(nick, host)
|
||||
sleep(2)
|
||||
name(nick)
|
||||
sleep(6)
|
||||
auth(nick, password)
|
||||
sleep(2)
|
||||
for chan in chans:
|
||||
join(chan)
|
||||
sleep(2)
|
||||
mode(nick)
|
||||
sleep(2)
|
||||
except Exception as err:
|
||||
print("FAIL: "+err)
|
||||
connect(host, port)
|
||||
sleep(2)
|
||||
register(nick, host)
|
||||
sleep(2)
|
||||
name(nick)
|
||||
sleep(6)
|
||||
auth(nick, password)
|
||||
sleep(2)
|
||||
mode(nick)
|
||||
sleep(2)
|
||||
for chan in chans:
|
||||
join(chan)
|
||||
sleep(2)
|
||||
|
||||
|
||||
def command_loop():
|
||||
@ -305,7 +295,7 @@ def command_loop():
|
||||
|
||||
elif msg == ".help":
|
||||
print("sending help")
|
||||
say(channel, "available commands: .nextrocket, .slap, .mate, .jn, .rep, .twitter, .trump, .konfuzius, .fml, .eurusd, .usdeur, .nslookup")
|
||||
say(channel, "available commands: .nextrocket, .slap, .mate, .hello, .jn, .rep, .konfuzius, .fml, .eurusd, .usdeur, .nslookup")
|
||||
|
||||
elif msg == ".nextrocket":
|
||||
try:
|
||||
@ -375,14 +365,14 @@ def command_loop():
|
||||
except:
|
||||
reason = "None"
|
||||
print("with no reason")
|
||||
if user == ircnick:
|
||||
say(channel, "You can't give rep to yourself. Selfish little prick!")
|
||||
continue
|
||||
try:
|
||||
acc_name = is_registered(user)
|
||||
give_acc = is_registered(ircnick)
|
||||
print("found account name for "+str(user)+": "+str(acc_name))
|
||||
if acc_name != None and give_acc != None:
|
||||
if acc_name == give_acc:
|
||||
say(channel, "You can't give rep to yourself. Selfish little prick!")
|
||||
continue
|
||||
give_rep(acc_name, user, give_acc, reason, channel)
|
||||
elif give_acc == None:
|
||||
say(channel, "You are not registered!")
|
||||
@ -460,13 +450,12 @@ def command_loop():
|
||||
except:
|
||||
say(channel, r+"You must specify a domain!")
|
||||
continue
|
||||
try:
|
||||
nstype = msg_parts[2]
|
||||
except:
|
||||
nstype = "A"
|
||||
nstype = msg_parts[2:]
|
||||
if not nstype:
|
||||
nstype = ["AAAA", "A"]
|
||||
print("got nslookup command with domain: "+str(nsdomain)+" and type: "+str(nstype))
|
||||
nsresult = nslookup(nsdomain, nstype)
|
||||
nslines = nsresult.split("\n")
|
||||
nslines = set(nsresult.split("\n"))
|
||||
for nsline in nslines:
|
||||
say(channel, y+" "+str(nsline))
|
||||
except Exception as err:
|
||||
@ -510,7 +499,11 @@ class fefe_thread(threading.Thread):
|
||||
fefe_check()
|
||||
|
||||
def main():
|
||||
start(host, port, nick, password, set(join_chans + fefe_chans))
|
||||
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()
|
||||
|
6
fml.py
6
fml.py
@ -3,16 +3,12 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
url = "http://www.fmylife.com/random"
|
||||
|
||||
|
||||
def get_fml(url):
|
||||
r = requests.get(url)
|
||||
data = r.text
|
||||
r.close
|
||||
soup = BeautifulSoup(data, 'html.parser')
|
||||
fml = soup.find("article", class_="art-panel").find_all("a")[2].string.strip().replace("\\", "").replace(" FML", "")
|
||||
fml = soup.select_one("article > a.block").string.strip().replace("\\", "").rstrip(" FML")
|
||||
del soup
|
||||
return fml
|
||||
|
||||
|
59
launch.py
59
launch.py
@ -10,61 +10,34 @@ from string import Template
|
||||
b = "\x0312"
|
||||
y = "\x038"
|
||||
|
||||
API_URL = "https://launchlibrary.net/1.2/launch/next/1"
|
||||
API_URL = "https://fdo.rocketlaunch.live/json/launches/next/1"
|
||||
|
||||
class launch(object):
|
||||
def api_request(self):
|
||||
request = urllib.request.Request(API_URL)
|
||||
response = urllib.request.urlopen(request).read()
|
||||
json_data = json.loads(response.decode('UTF-8'))
|
||||
return json_data['launches'][0]
|
||||
return json_data['result'][0]
|
||||
|
||||
def rocket_name(self, json_data):
|
||||
try:
|
||||
name = json_data['rocket']['name']
|
||||
name = json_data['vehicle']['name']
|
||||
except:
|
||||
name = "UNKNOWN"
|
||||
return name
|
||||
|
||||
def mission_name(self, json_data):
|
||||
try:
|
||||
name = json_data['missions'][0]['name']
|
||||
name = json_data['name']
|
||||
except:
|
||||
name = "UNKNOWN"
|
||||
return name
|
||||
|
||||
def net_raw_utc(self, json_data):
|
||||
time_utc_string = json_data['net']
|
||||
try:
|
||||
time_utc = datetime.datetime.strptime(time_utc_string, '%B %d, %Y %H:%M:%S %Z')
|
||||
except TypeError:
|
||||
time_utc = datetime.datetime(*(time.strptime(time_utc_string, '%B %d, %Y %H:%M:%S %Z')[0:6]))
|
||||
time_utc_string = json_data['t0']
|
||||
time_utc = datetime.datetime.fromisoformat(time_utc_string)
|
||||
return time_utc
|
||||
|
||||
def net(self, json_data):
|
||||
time_utc_string = json_data['net']
|
||||
try:
|
||||
time_utc = datetime.datetime.strptime(time_utc_string, '%B %d, %Y %H:%M:%S %Z')
|
||||
except TypeError:
|
||||
time_utc = datetime.datetime(*(time.strptime(time_utc_string, '%B %d, %Y %H:%M:%S %Z')[0:6]))
|
||||
time_local = pytz.utc.localize(time_utc).astimezone(pytz.timezone('Europe/Berlin'))
|
||||
time = datetime.datetime.strftime(time_local, 'NET %d.%m.%Y')
|
||||
return time
|
||||
|
||||
def get_status(self, json_data):
|
||||
tbd_stat = json_data['tbdtime']
|
||||
hold_stat = json_data['inhold']
|
||||
go_stat = json_data['status']
|
||||
if tbd_stat == 1:
|
||||
status = "TBD"
|
||||
elif hold_stat == 1:
|
||||
status = "HOLD"
|
||||
elif go_stat == 1:
|
||||
status = "GO"
|
||||
else:
|
||||
status = "UNKNOWN"
|
||||
return status
|
||||
|
||||
|
||||
class DeltaTemplate(Template):
|
||||
delimiter = "%"
|
||||
@ -86,18 +59,10 @@ def next_launch():
|
||||
json_data = l.api_request()
|
||||
rocket = l.rocket_name(json_data)
|
||||
mission = l.mission_name(json_data)
|
||||
status = l.get_status(json_data)
|
||||
if status != "GO":
|
||||
deltastring = l.net(json_data)
|
||||
else:
|
||||
launch_time = l.net_raw_utc(json_data)
|
||||
now = datetime.datetime.utcnow().replace(microsecond=0)
|
||||
if launch_time > now:
|
||||
timedelta = launch_time - now
|
||||
t_string = "-"
|
||||
else:
|
||||
timedelta = now - launch_time
|
||||
t_string = "+"
|
||||
deltastring = strfdelta(timedelta, "T"+t_string+"%D:%H:%M:%S")
|
||||
launch_time = l.net_raw_utc(json_data)
|
||||
now = datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0)
|
||||
timedelta = abs(launch_time - now)
|
||||
t_string = "-" if launch_time > now else "+"
|
||||
deltastring = strfdelta(timedelta, "T"+t_string+"%D:%H:%M:%S")
|
||||
del l
|
||||
return rocket, mission, status, deltastring
|
||||
return rocket, mission, deltastring
|
||||
|
26
nslookup.py
26
nslookup.py
@ -2,30 +2,30 @@
|
||||
|
||||
import dns.resolver
|
||||
|
||||
def nslookup(domain, typ="A"):
|
||||
def nslookup(domain, types=["AAAA", "A"]):
|
||||
result = ""
|
||||
rcount = 0
|
||||
try:
|
||||
answer = dns.resolver.query(domain, typ)
|
||||
for rdata in answer:
|
||||
if rcount > 0:
|
||||
result += "\n"
|
||||
if hasattr(rdata, 'exchange'):
|
||||
result += str(rdata.preference)+" "+str(rdata.exchange)
|
||||
rcount += 1
|
||||
else:
|
||||
result += str(rdata)
|
||||
rcount += 1
|
||||
for typ in types:
|
||||
answer = dns.resolver.resolve(domain, typ)
|
||||
for rdata in answer:
|
||||
if rcount > 0:
|
||||
result += "\n"
|
||||
if hasattr(rdata, 'exchange'):
|
||||
result += str(rdata.preference)+" "+str(rdata.exchange)
|
||||
rcount += 1
|
||||
else:
|
||||
result += str(rdata)
|
||||
rcount += 1
|
||||
except dns.resolver.NXDOMAIN as err:
|
||||
result = str(err)
|
||||
except Exception as err:
|
||||
result = "Error"
|
||||
print("nslookup error! - "+str(err))
|
||||
del answer
|
||||
return result
|
||||
|
||||
def main():
|
||||
print(nslookup("elmo.space", "AAAA"))
|
||||
print(nslookup("elmo.space"))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Reference in New Issue
Block a user