Added helper function msgsplit
Added command fefe Added MapQuest and Fefe to .help Minor fix
This commit is contained in:
parent
c079093af9
commit
fc1a9a04d5
1 changed files with 36 additions and 2 deletions
38
main.py
38
main.py
|
@ -272,6 +272,11 @@ class pircbot():
|
||||||
return textstring.decode(self.encodings[0], 'ignore')
|
return textstring.decode(self.encodings[0], 'ignore')
|
||||||
|
|
||||||
|
|
||||||
|
# splits messages into parts with a specific maximal length
|
||||||
|
def msgsplit(self, msg, length=400):
|
||||||
|
return [msg[i:i+length] for i in range(0, len(msg), length)]
|
||||||
|
|
||||||
|
|
||||||
# checks if a given user may execute a given command
|
# checks if a given user may execute a given command
|
||||||
def check_privileges(self, usermask, command, log=True):
|
def check_privileges(self, usermask, command, log=True):
|
||||||
for user, privs in self.users.items():
|
for user, privs in self.users.items():
|
||||||
|
@ -391,6 +396,8 @@ class pircbot():
|
||||||
choose <choice1>, <choice2>[, <choice3>[, ...]] -- Let the bot decide!\n\
|
choose <choice1>, <choice2>[, <choice3>[, ...]] -- Let the bot decide!\n\
|
||||||
DuckDuckGo, ddg <query> -- Ask the DuckDuckGo Instant Answer API\n\
|
DuckDuckGo, ddg <query> -- Ask the DuckDuckGo Instant Answer API\n\
|
||||||
Forecast, fc <query> -- Query Forecast.io\n\
|
Forecast, fc <query> -- Query Forecast.io\n\
|
||||||
|
MapQuest, mq, OpenStreetMap, osm <query> -- Get lat and lon for a place\n\
|
||||||
|
Fefe [<id>] -- Show a given or the lastest post in Fefes Blog\n\
|
||||||
" % (
|
" % (
|
||||||
self.cmdprefix,
|
self.cmdprefix,
|
||||||
self.user["nick"]
|
self.user["nick"]
|
||||||
|
@ -480,7 +487,7 @@ class pircbot():
|
||||||
"Precipitation Intensity: %s mm/h" % rj["currently"]["precipIntensity"], in_query_type)
|
"Precipitation Intensity: %s mm/h" % rj["currently"]["precipIntensity"], in_query_type)
|
||||||
if "precipType" in rj["currently"]: self.reply(origin, source,
|
if "precipType" in rj["currently"]: self.reply(origin, source,
|
||||||
"Precipitation Type: %s" % rj["currently"]["precipType"], in_query_type)
|
"Precipitation Type: %s" % rj["currently"]["precipType"], in_query_type)
|
||||||
self.reply(origin, source,
|
if "visibility" in rj["currently"]: self.reply(origin, source,
|
||||||
"Visibility: %s km" % rj["currently"]["visibility"], in_query_type)
|
"Visibility: %s km" % rj["currently"]["visibility"], in_query_type)
|
||||||
self.reply(origin, source,
|
self.reply(origin, source,
|
||||||
"Humidity: %s %%" % (rj["currently"]["humidity"]*100), in_query_type)
|
"Humidity: %s %%" % (rj["currently"]["humidity"]*100), in_query_type)
|
||||||
|
@ -497,7 +504,7 @@ class pircbot():
|
||||||
return "Error while querying Forecast.io, got HTTP-Status %i" % rp.getcode()
|
return "Error while querying Forecast.io, got HTTP-Status %i" % rp.getcode()
|
||||||
else:
|
else:
|
||||||
return "Usage: %s <lat> <lon>" % command
|
return "Usage: %s <lat> <lon>" % command
|
||||||
# MapQuest, mq, OpenStreetMap, osm
|
# MapQuest, mq, OpenStreetMap, osm <query>
|
||||||
elif command in ("mapquest", "mq", "openstreetmap", "osm") and self.mapquest_cfg["Active"] == "1":
|
elif command in ("mapquest", "mq", "openstreetmap", "osm") and self.mapquest_cfg["Active"] == "1":
|
||||||
if numparams==0:
|
if numparams==0:
|
||||||
return "You didn't ask anything..."
|
return "You didn't ask anything..."
|
||||||
|
@ -524,6 +531,33 @@ class pircbot():
|
||||||
return "(Nominatim Search Courtesy of MapQuest <http://www.mapquest.com/>)"
|
return "(Nominatim Search Courtesy of MapQuest <http://www.mapquest.com/>)"
|
||||||
else:
|
else:
|
||||||
return "Error while querying MapQuest, got HTTP-Status %i" % rp.getcode()
|
return "Error while querying MapQuest, got HTTP-Status %i" % rp.getcode()
|
||||||
|
# Fefe <id>
|
||||||
|
elif command == "fefe":
|
||||||
|
if numparams>1:
|
||||||
|
return "Waddayawannasee? (The one and only optional argument needed is the ID of the blog post. If it is omitted, the last post will be shown.)"
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
if numparams==1:
|
||||||
|
rp = urlopen("http://blog.fefe.de/?ts=%s" % quote_plus(params[0]))
|
||||||
|
else:
|
||||||
|
rp = urlopen("http://blog.fefe.de/")
|
||||||
|
except Exception as e:
|
||||||
|
self.log.error("Error while querying Fefe: %s" % e)
|
||||||
|
return "Error while querying Fefe: %s" % e
|
||||||
|
if rp.getcode() == 200:
|
||||||
|
try:
|
||||||
|
rpd = str(rp.readall(), "utf-8")
|
||||||
|
m = re.search(r"<li>(.*?)<\/(?:li|ul)>", "".join(rpd.splitlines())).groups()[0]
|
||||||
|
print(m+"\n\n")
|
||||||
|
m = " ".join((re.split(r"<.+?>", m)))[6:]
|
||||||
|
if len(m)>400:
|
||||||
|
mmlen = 400
|
||||||
|
for l in self.msgsplit(m):
|
||||||
|
print(l)
|
||||||
|
self.reply(origin, source, l, in_query_type)
|
||||||
|
except Exception as e:
|
||||||
|
self.log.warning("Suspectious things happend while handling a response from fefes blog, but it's probably just an incorrect blogpost-id: %s" % e)
|
||||||
|
return "Nothing matched... (If you're sure your id was correct, see error log)"
|
||||||
|
|
||||||
### IRC ###
|
### IRC ###
|
||||||
# join <channel>
|
# join <channel>
|
||||||
|
|
Loading…
Reference in a new issue