|
|
@ -1,44 +1,31 @@ |
|
|
|
|
|
|
|
|
|
|
|
#!/usr/bin/env python3 |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
|
|
|
# To run this bot: |
|
|
|
# $ python3 logbot.py |
|
|
|
""" |
|
|
|
This bot replies to a specific word. |
|
|
|
On line 42, you can edit the word-to-be-responded-to after "if '": |
|
|
|
if 'target-word' in msg['body']: |
|
|
|
On line 44, you can edit the response options after "wordslist = ['": |
|
|
|
wordslist = ['a response to the target-word.'] |
|
|
|
|
|
|
|
# This bot replies to a specific word — see line 67. |
|
|
|
To run this bot, type the following command in your terminal: |
|
|
|
python3 spark.py -d -j administratorbot@conversejs.org -r botsofconduct@muc.vvvvvvaria.org -n sparkbot -p testing |
|
|
|
""" |
|
|
|
|
|
|
|
import logging |
|
|
|
from getpass import getpass |
|
|
|
from argparse import ArgumentParser |
|
|
|
|
|
|
|
import slixmpp |
|
|
|
import random |
|
|
|
import ssl, os, requests, urllib |
|
|
|
|
|
|
|
class MUCBot(slixmpp.ClientXMPP): |
|
|
|
""" |
|
|
|
A simple Slixmpp bot that will save images |
|
|
|
and messages that are marked with @bot to a folder. |
|
|
|
""" |
|
|
|
|
|
|
|
def __init__(self, jid, password, room, nick, output): |
|
|
|
def __init__(self, jid, password, room, nick): |
|
|
|
slixmpp.ClientXMPP.__init__(self, jid, password) |
|
|
|
|
|
|
|
self.room = room |
|
|
|
self.nick = nick |
|
|
|
self.output = output |
|
|
|
|
|
|
|
# The session_start event will be triggered when |
|
|
|
# the bot establishes its connection with the server |
|
|
|
# and the XML logs are ready for use. We want tob |
|
|
|
# listen for this event so that we we can initialize |
|
|
|
# our roster. |
|
|
|
self.add_event_handler("session_start", self.start) |
|
|
|
|
|
|
|
# The groupchat_message event is triggered whenever a message |
|
|
|
# stanza is received from any chat room. If you also also |
|
|
|
# register a handler for the 'message' event, MUC messages |
|
|
|
# will be processed by both handlers. |
|
|
|
self.add_event_handler("groupchat_message", self.muc_message) |
|
|
|
|
|
|
|
|
|
|
@ -47,34 +34,16 @@ class MUCBot(slixmpp.ClientXMPP): |
|
|
|
self.send_presence() |
|
|
|
|
|
|
|
# https://xmpp.org/extensions/xep-0045.html |
|
|
|
self.plugin['xep_0045'].join_muc(self.room, |
|
|
|
self.nick, |
|
|
|
# If a room password is needed, use: |
|
|
|
# password=the_room_password, |
|
|
|
wait=True) |
|
|
|
self.plugin['xep_0045'].join_muc(self.room, self.nick, wait=True) |
|
|
|
|
|
|
|
def muc_message(self, msg): |
|
|
|
# Some inspection commands |
|
|
|
#print('Message: {}'.format(msg)) |
|
|
|
|
|
|
|
# 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: |
|
|
|
|
|
|
|
# Check if output folder exists |
|
|
|
if not os.path.exists(self.output): |
|
|
|
os.mkdir(self.output) |
|
|
|
|
|
|
|
# everytime someone types target-word, the bot replies: |
|
|
|
if 'target-word' in msg['body']: |
|
|
|
|
|
|
|
import random |
|
|
|
wordslist = ['a response to the target-word.'] |
|
|
|
|
|
|
|
# reply from the bot |
|
|
|
self.send_message(mto=self.room, |
|
|
|
|
|
|
|
mbody= random.choice(wordslist), |
|
|
|
mtype='groupchat') |
|
|
|
# Everytime someone types this word or expression, the bot replies. You can edit it here: |
|
|
|
if 'collective' in msg['body']: |
|
|
|
# The list of responses one line below can be expanded with the following format: ['text','text','text'] |
|
|
|
wordslist = ['conditions'] |
|
|
|
# The bot will respond with one of the options at random: |
|
|
|
self.send_message(mto=self.room,mbody= random.choice(wordslist), mtype='groupchat') |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
@ -118,13 +87,11 @@ if __name__ == '__main__': |
|
|
|
args.room = input("MUC room: ") |
|
|
|
if args.nick is None: |
|
|
|
args.nick = input("MUC nickname: ") |
|
|
|
if args.output is None: |
|
|
|
args.output = input("Output folder: ") |
|
|
|
|
|
|
|
# Setup the MUCBot and register plugins. Note that while plugins may |
|
|
|
# have interdependencies, the order in which you register them does |
|
|
|
# not matter. |
|
|
|
xmpp = MUCBot(args.jid, args.password, args.room, args.nick, args.output) |
|
|
|
xmpp = MUCBot(args.jid, args.password, args.room, args.nick) |
|
|
|
xmpp.register_plugin('xep_0030') # Service Discovery |
|
|
|
xmpp.register_plugin('xep_0045') # Multi-User Chat |
|
|
|
xmpp.register_plugin('xep_0199') # XMPP Ping |
|
|
@ -134,4 +101,14 @@ if __name__ == '__main__': |
|
|
|
xmpp.connect() |
|
|
|
xmpp.process() |
|
|
|
|
|
|
|
""" |
|
|
|
Slixmpp: The Slick XMPP Library |
|
|
|
Copyright (C) 2010 Nathanael C. Fritz |
|
|
|
This file is part of Slixmpp. |
|
|
|
|
|
|
|
See the file LICENSE for copying permission. |
|
|
|
https://lab.louiz.org/poezio/slixmpp/blob/master/LICENSE |
|
|
|
|
|
|
|
The code has been modified for the Collective Conditions work session in Brussels, 2019, by Cristina Cochior and Joana Chicau. |
|
|
|
http://constantvzw.org/site/-Collective-Conditions,220-.html |
|
|
|
""" |
|
|
|