Browse Source

oops, included changes made on the server earlier

pull/5/head
manetta 6 years ago
parent
commit
613fe74f07
  1. 64
      logbot.py

64
logbot.py

@ -1,19 +1,9 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""
Slixmpp: The Slick XMPP Library
Copyright (C) 2010 Nathanael C. Fritz
This file is part of Slixmpp.
See the file LICENSE for copying permission.
"""
# Code source: https://git.poez.io/slixmpp/tree/examples/muc.py
# To run this bot: # To run this bot:
# $ python3 logbot.py --jid username@yourdomainname.ext --password password --room channel@groups.domainname.ext --nick nickname --output ./output/ # $ python3 logbot.py
# The output folder of this bot currently is: /var/www/logs/digital-autonomy
import logging import logging
from getpass import getpass from getpass import getpass
@ -50,14 +40,6 @@ class MUCBot(slixmpp.ClientXMPP):
def start(self, event): def start(self, event):
"""
Process the session_start event.
Typical actions for the session_start event are
requesting the roster and broadcasting an initial
presence stanza.
"""
self.get_roster() self.get_roster()
self.send_presence() self.send_presence()
@ -68,54 +50,30 @@ class MUCBot(slixmpp.ClientXMPP):
# password=the_room_password, # password=the_room_password,
wait=True) wait=True)
def muc_message(self, msg): # Send a message to the room
""" self.send_message(mto=self.room, mbody='Hello! Logbot here. I\'m here to log all the images that are send to this group. You can also log text messages, by including @bot in your message. Happy logging! PS. you can access the logs at https://vvvvvvaria.org/logs/', mtype='groupchat')
Process incoming message stanzas from any chat room. Be aware
that if you also have any handlers for the 'message' event,
message stanzas may be processed by both handlers, so check
the 'type' attribute when using a 'message' event handler.
Whenever the bot's nickname is mentioned, respond to
the message.
IMPORTANT: Always check that a message is not from yourself,
otherwise you will create an infinite loop responding
to your own messages.
This handler will reply to messages that mention
the bot's nickname.
Arguments:
msg -- The received message stanza. See the documentation
for stanza objects and the Message stanza to see
how it may be used.
"""
def muc_message(self, msg):
# Some inspection commands # Some inspection commands
print('Message: {}'.format(msg)) # print('Message: {}'.format(msg))
# print('\nMessage TYPE:{}'.format(msg['type']))
# print('\nMessage body:{}'.format(msg['body']))
# print('\nMessage OOB:{}'.format(msg['oob']))
# print('\nMessage OOB URL:{}'.format(msg['oob']['url']))
# print('\nMessage MUCK NICK:{}'.format(msg['mucnick']))
# Always check that a message is not the bot itself, otherwise you will create an infinite loop responding to your own messages. # Always check that a message is not the bot itself, otherwise you will create an infinite loop responding to your own messages.
if msg['mucnick'] != self.nick: if msg['mucnick'] != self.nick:
# Check if output folder exists
if not os.path.exists(self.output):
os.mkdir(self.output)
# Check if an OOB URL is included in the stanza (which is how an image is sent) # Check if an OOB URL is included in the stanza (which is how an image is sent)
# (OOB object - https://xmpp.org/extensions/xep-0066.html#x-oob) # (OOB object - https://xmpp.org/extensions/xep-0066.html#x-oob)
if len(msg['oob']['url']) > 0: if len(msg['oob']['url']) > 0:
# Check if output folder exists
if not os.path.exists(self.output):
os.mkdir(self.output)
# Send a reply # Send a reply
self.send_message(mto=self.room, self.send_message(mto=self.room,
mbody="Super, our log is growing. Your image is added!", mbody="Super, our log is growing. Your image is added!",
mtype='groupchat') mtype='groupchat')
Save the image to the output folder # Save the image to the output folder
url = msg['oob']['url'] # grep the url in the message url = msg['oob']['url'] # grep the url in the message
filename = os.path.basename(url) # grep the filename in the url filename = os.path.basename(url) # grep the filename in the url
output_path = os.path.join(output, filename) output_path = os.path.join(output, filename)

Loading…
Cancel
Save