Compare commits

..

No commits in common. "master" and "master" have entirely different histories.

2 changed files with 37 additions and 38 deletions

View File

@ -1,8 +1,6 @@
> note: merged into https://git.vvvvvvaria.org/varia/bots
# logbot # logbot
A small XMPP bot written in Python (using the slixmpp library) that logs all images and messages with the mentioning of *@bot* to an HTML page, to allow collaborative log writing over time. A small XMPP bot written in Python (using the slixmpp library), that logs all images and messages with the mentioning of *@bot*.
To run it: To run it:
@ -10,7 +8,7 @@ To run it:
Dependencies: Dependencies:
$ sudo pip3 install slixmpp beautifulsoup4 $ sudo pip3 install slixmpp
--- ---

View File

@ -82,8 +82,8 @@ class MUCBot(slixmpp.ClientXMPP):
f.write(u.read()) # write image to file f.write(u.read()) # write image to file
f.close() # close the output file f.close() # close the output file
# Add the image to the log # Add image to log
img = '<img class="image" src="{}">'.format(filename) img = '<img class="image" src="{}">'.format(msg['oob']['url'])
log = 'log.html' log = 'log.html'
log_path = os.path.join(self.output, log) log_path = os.path.join(self.output, log)
f = open(log_path, 'a+') f = open(log_path, 'a+')
@ -91,7 +91,7 @@ class MUCBot(slixmpp.ClientXMPP):
f.close() f.close()
# Include messages in the log (only when '@bot' is used in the message) # Include messages in the log (only when '#publish' is used in the message)
if '@bot' in msg['body']: if '@bot' in msg['body']:
# reply from the bot # reply from the bot
@ -99,7 +99,7 @@ class MUCBot(slixmpp.ClientXMPP):
mbody="Noted! And added to the log. Thanks {}!".format(msg['mucnick']), mbody="Noted! And added to the log. Thanks {}!".format(msg['mucnick']),
mtype='groupchat') mtype='groupchat')
# Add the message to the log! # Add message to log
message = '<p class="message">{}</p>'.format(msg['body'].replace('@bot','')) message = '<p class="message">{}</p>'.format(msg['body'].replace('@bot',''))
log = 'log.html' log = 'log.html'
log_path = os.path.join(self.output, log) log_path = os.path.join(self.output, log)
@ -107,14 +107,15 @@ class MUCBot(slixmpp.ClientXMPP):
f.write(message+'\n') f.write(message+'\n')
f.close() f.close()
if '/book' in msg['body']: # Check if this is a book ... if '/book' in msg['body']: # Check if this is a book
self.send_message(mto=self.room, self.send_message(mto=self.room,
mbody="Oh a book, that's cool! Thanks {}!".format(msg['mucnick']), mbody="Oh a book, that's cool! Thanks {}!".format(msg['mucnick']),
mtype='groupchat') mtype='groupchat')
# Start of book feature
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import requests
import re import re
book = msg['body'].replace('@bot', '').replace('/book', '') book = msg['body'].replace('@bot', '').replace('/book', '')