Compare commits
20 Commits
74a8f3bfe7
...
b3364d99b0
Author | SHA1 | Date | |
---|---|---|---|
b3364d99b0 | |||
fec0ee4b10 | |||
cc274a5d96 | |||
45809ff5ec | |||
3fa1bb4c92 | |||
125528c567 | |||
a44082180c | |||
c018534c0e | |||
bb67f98d4b | |||
b06a606fd7 | |||
5ed96b0ddf | |||
c875a4a17d | |||
2cb3eec4aa | |||
818110e485 | |||
428814b318 | |||
a291010ae1 | |||
e6f8dbd1e8 | |||
7009169145 | |||
bd5621f9bd | |||
ad96b14445 |
137
bert.py
137
bert.py
@ -1,45 +1,33 @@
|
||||
#!/usr/bin/python3 -u
|
||||
|
||||
import gc
|
||||
import socket
|
||||
import ssl
|
||||
import sys
|
||||
import os
|
||||
from time import sleep
|
||||
import launch
|
||||
import tweepy
|
||||
import threading
|
||||
import re
|
||||
import html
|
||||
import json
|
||||
import requests
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
from datetime import datetime, timedelta
|
||||
import konfuzius
|
||||
import urlinfo
|
||||
import fml
|
||||
import string
|
||||
import random
|
||||
from flask import Flask, request
|
||||
from nslookup import nslookup
|
||||
import rss
|
||||
|
||||
version = "v0.8"
|
||||
version = "v0.9"
|
||||
|
||||
# IRC settings
|
||||
host = ""
|
||||
port =
|
||||
nick = "bert"
|
||||
nick = "huan"
|
||||
password = ""
|
||||
chan = ""
|
||||
fefe_chans = [""]
|
||||
|
||||
# Twitter settings
|
||||
consumer_key = ""
|
||||
consumer_secret = ""
|
||||
access_token = ""
|
||||
access_secret = ""
|
||||
|
||||
# fml endpoint
|
||||
fml_url = "http://www.fmylife.com/random"
|
||||
|
||||
@ -50,9 +38,9 @@ y = "\x038"
|
||||
r = "\x034"
|
||||
g = "\x033"
|
||||
|
||||
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
irc = ssl.wrap_socket(s)
|
||||
context = ssl.create_default_context()
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
irc = context.wrap_socket(sock, server_hostname=host)
|
||||
|
||||
|
||||
# Currency API
|
||||
@ -133,6 +121,12 @@ def mode(nick):
|
||||
except Exception as err:
|
||||
print("Failed! "+err)
|
||||
|
||||
print("Setting mode -x")
|
||||
try:
|
||||
sendRaw("MODE "+nick+" -x\n")
|
||||
except Exception as err:
|
||||
print("Failed! "+err)
|
||||
|
||||
|
||||
def part(chan):
|
||||
print("Leaving channel "+chan)
|
||||
@ -195,19 +189,13 @@ def yon():
|
||||
return answer
|
||||
|
||||
|
||||
def url_title(url):
|
||||
title = urlinfo.get_title(url).encode("UTF-8").decode("UTF-8")
|
||||
return title
|
||||
|
||||
|
||||
def is_registered(username):
|
||||
try:
|
||||
sendRaw("WHOIS "+str(username)+"\n")
|
||||
user_info = getMessage()
|
||||
regex = r"330 "+str(nick)+" "+str(username)+" [a-zA-Z0-9]+ :is logged in as"
|
||||
regex = r"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:
|
||||
print(match.group(0))
|
||||
acc_name = match.group(0).split()[3]
|
||||
return acc_name
|
||||
except Exception as err:
|
||||
@ -271,7 +259,7 @@ def ping(msg):
|
||||
sendRaw("PONG :"+msg+"\n")
|
||||
|
||||
|
||||
def start(host, port, nick, password, chan):
|
||||
def start(host, port, nick, password, chans):
|
||||
try:
|
||||
connect(host, port)
|
||||
sleep(2)
|
||||
@ -281,7 +269,7 @@ def start(host, port, nick, password, chan):
|
||||
sleep(6)
|
||||
auth(nick, password)
|
||||
sleep(2)
|
||||
for chan in fefe_chans:
|
||||
for chan in chans:
|
||||
join(chan)
|
||||
sleep(2)
|
||||
mode(nick)
|
||||
@ -294,9 +282,6 @@ def command_loop():
|
||||
while True:
|
||||
try:
|
||||
data = getData()
|
||||
with open("bert.log", "a") as f:
|
||||
f.write(data)
|
||||
f.close()
|
||||
ircmsg = data.strip("\n\r")
|
||||
if ircmsg.find("PING :") != -1:
|
||||
pingstring = ircmsg.strip("PING :")
|
||||
@ -314,7 +299,7 @@ def command_loop():
|
||||
print("direct message received")
|
||||
if msg == "\x01VERSION\x01":
|
||||
print("got ctcp version request")
|
||||
notice(ircnick, "\x01VERSION BertBot "+version+"\x01")
|
||||
notice(ircnick, "\x01VERSION HuanBot (fork of BertBot) "+version+"\x01")
|
||||
elif msg.startswith("\x01PING"):
|
||||
print("got ctcp ping request")
|
||||
pingstring = msg.split()[1]
|
||||
@ -428,31 +413,6 @@ def command_loop():
|
||||
except Exception as err:
|
||||
print("Error getting rep! - "+str(err))
|
||||
|
||||
elif msg.startswith(".twitter"):
|
||||
try:
|
||||
twittername = msg.split()[1]
|
||||
try:
|
||||
lasttweet = api.user_timeline(screen_name=twittername, count=1, tweet_mode="extended")[0]
|
||||
twit = lasttweet.full_text
|
||||
user = lasttweet.user.name
|
||||
text = html.unescape(re.sub(r'\n', ' ', twit))
|
||||
say(channel, b+user+": "+c+text)
|
||||
except Exception as err:
|
||||
print("Could not get last tweet! "+err)
|
||||
except:
|
||||
say(channel, "You have to give me a username")
|
||||
|
||||
elif msg.startswith(".trump"):
|
||||
try:
|
||||
twittername = "realdonaldtrump"
|
||||
lasttweet = api.user_timeline(screen_name=twittername, count=1, tweet_mode="extended")[0]
|
||||
twit = lasttweet.full_text
|
||||
user = lasttweet.user.name
|
||||
text = html.unescape(re.sub(r'\n', ' ', twit))
|
||||
say(channel, b+user+": "+c+text)
|
||||
except Exception as err:
|
||||
print("Could not get last tweet! "+err)
|
||||
|
||||
elif msg.startswith(".konfuzius"):
|
||||
try:
|
||||
quote = konfuzius.random_quote()
|
||||
@ -461,7 +421,7 @@ def command_loop():
|
||||
say(channel, "Error :(")
|
||||
|
||||
elif msg == ".quit":
|
||||
if ircnick == "elmo":
|
||||
if ircnick == "jkhsjdhjs":
|
||||
say(channel, "Flying to mars...")
|
||||
print("got quit command. exiting...")
|
||||
part(channel)
|
||||
@ -470,7 +430,7 @@ def command_loop():
|
||||
say(channel, "You are not my master!")
|
||||
|
||||
elif msg.startswith(".say"):
|
||||
if ircnick == "elmo":
|
||||
if ircnick == "jkhsjdhjs":
|
||||
try:
|
||||
sayit = msg.split(" ", 1)[1]
|
||||
say(channel, str(sayit))
|
||||
@ -481,7 +441,7 @@ def command_loop():
|
||||
say(channel, "You are not my master!")
|
||||
|
||||
elif msg.startswith(".debug"):
|
||||
if ircnick == "elmo":
|
||||
if ircnick == "jkhsjdhjs":
|
||||
try:
|
||||
debugmsg = msg.split(" ", 1)[1]
|
||||
raw(debugmsg)
|
||||
@ -491,30 +451,6 @@ def command_loop():
|
||||
else:
|
||||
say(channel, "You are not my master!")
|
||||
|
||||
elif "twitter.com" in msg:
|
||||
try:
|
||||
p = re.compile('twitter\.com/[A-Za-z0-9]*/status/[0-9]*')
|
||||
tweet_link = p.search(msg).group(0)
|
||||
status_id = tweet_link.split("/")[3]
|
||||
status = api.get_status(status_id, tweet_mode="extended")
|
||||
user = status.user.name
|
||||
text = status.full_text
|
||||
print("found twitter link\n"+user+" - "+text)
|
||||
say(channel, b+user+": "+c+text)
|
||||
except Exception as err:
|
||||
print("twitter link invalid "+str(err))
|
||||
elif urlinfo.is_url(msg) != None:
|
||||
try:
|
||||
url = urlinfo.is_url(msg)
|
||||
ignore = ["pr0gramm", "w0bm", "f0ck", "twitter", "youtube", "youtu.be"]
|
||||
if any(ign in url for ign in ignore):
|
||||
pass
|
||||
else:
|
||||
title = urlinfo.get_title(url)
|
||||
print("Found URL and got title "+str(title))
|
||||
say(channel, b+"Title: "+c+title)
|
||||
except Exception as err:
|
||||
print("Error getting URL title - "+str(err))
|
||||
elif msg == ".fml":
|
||||
try:
|
||||
fml_string = fml.get_fml(fml_url)
|
||||
@ -563,17 +499,6 @@ def fefe_check():
|
||||
sleep(300)
|
||||
|
||||
|
||||
def gc_cycle():
|
||||
while True:
|
||||
try:
|
||||
# fire the garbage collector
|
||||
gc.set_debug(gc.DEBUG_STATS)
|
||||
gc.collect()
|
||||
time.sleep(120)
|
||||
except Exception as err:
|
||||
print("Error in garbage collector! - "+str(err))
|
||||
|
||||
|
||||
class command_thread(threading.Thread):
|
||||
def __init__(self, threadID):
|
||||
threading.Thread.__init__(self)
|
||||
@ -590,30 +515,14 @@ class fefe_thread(threading.Thread):
|
||||
print("Starting fefe thread...")
|
||||
fefe_check()
|
||||
|
||||
class gc_thread(threading.Thread):
|
||||
def __init__(self, threadID):
|
||||
threading.Thread.__init__(self)
|
||||
self.threadID = threadID
|
||||
def run(self):
|
||||
print("Starting garbage collector thread...")
|
||||
gc_cycle()
|
||||
|
||||
def main():
|
||||
start(host, port, nick, password, chan)
|
||||
global api
|
||||
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
|
||||
auth.set_access_token(access_token, access_secret)
|
||||
api = tweepy.API(auth)
|
||||
start(host, port, nick, password, set(join_chans + fefe_chans))
|
||||
thread_command = command_thread(1)
|
||||
thread_fefe = fefe_thread(2)
|
||||
thread_gc = gc_thread(3)
|
||||
#thread_fefe = fefe_thread(2)
|
||||
thread_command.start()
|
||||
sleep(2)
|
||||
thread_fefe.start()
|
||||
sleep(2)
|
||||
thread_gc.start()
|
||||
#sleep(2)
|
||||
#thread_fefe.start()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
gc.enable()
|
||||
main()
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
import re
|
||||
import random
|
||||
import json
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
5
requirements.txt
Normal file
5
requirements.txt
Normal file
@ -0,0 +1,5 @@
|
||||
pytz
|
||||
beautifulsoup4~=4.11
|
||||
dnspython~=2.2
|
||||
feedparser~=6.0
|
||||
requests~=2.0
|
5
rss.py
5
rss.py
@ -3,16 +3,11 @@
|
||||
|
||||
import feedparser
|
||||
import time
|
||||
from subprocess import check_output
|
||||
import sys
|
||||
|
||||
def check():
|
||||
feed_name = 'fefe'
|
||||
url = 'https://blog.fefe.de/rss.xml'
|
||||
|
||||
#feed_name = sys.argv[1]
|
||||
#url = sys.argv[2]
|
||||
|
||||
db = 'rss_feeds.db'
|
||||
limit = 12 * 3600 * 1000
|
||||
|
||||
|
1
tweepy
1
tweepy
@ -1 +0,0 @@
|
||||
Subproject commit 2efe385fc69385b57733f747ee62e6be12a1338b
|
Loading…
Reference in New Issue
Block a user