Browse Source

Add the rest of the xbotlib bots

master
decentral1se 5 months ago
parent
commit
92d4f9f3e7
No known key found for this signature in database GPG Key ID: 5E2EF5A63E3718CC
  1. BIN
      echobot/avatar.png
  2. 4
      echobot/echobot.conf
  3. 26
      echobot/echobot.py
  4. BIN
      glossbot.xbotlib/avatar.png
  5. 4
      glossbot.xbotlib/glossbot.conf
  6. 90
      glossbot.xbotlib/glossbot.py
  7. BIN
      logsbot/avatar.png
  8. 13
      logsbot/index.html.j2
  9. 4
      logsbot/logsbot.conf
  10. 37
      logsbot/logsbot.py
  11. BIN
      whisperbot.xbotlib/avatar.png
  12. 4
      whisperbot.xbotlib/whisperbot.conf
  13. 21
      whisperbot.xbotlib/whisperbot.py

BIN
echobot/avatar.png

After

Width: 64  |  Height: 64  |  Size: 3.3 KiB

4
echobot/echobot.conf

@ -0,0 +1,4 @@
[echobot]
account = echobot@vvvvvvaria.org
nick = echobot
rooms = ibugev@muc.vvvvvvaria.org, xbotlibtest@muc.vvvvvvaria.org

26
echobot/echobot.py

@ -0,0 +1,26 @@
from xbotlib import Bot
class EchoBot(Bot):
"""Responds with whatever you send.
Simply direct message the bot and see if you get back what you sent. It
also works in group chats but in this case you need to summon the bot using
its nickname.
"""
help = "I echo messages back 🖖️"
def direct(self, message):
"""Send back whatever we receive."""
self.reply(message.text, to=message.sender)
def group(self, message):
"""Send back whatever receive in group chats."""
if message.url:
return
self.reply(message.content, room=message.room)
EchoBot()

BIN
glossbot.xbotlib/avatar.png

After

Width: 64  |  Height: 64  |  Size: 5.4 KiB

4
glossbot.xbotlib/glossbot.conf

@ -0,0 +1,4 @@
[glossbot]
account = glossbot@vvvvvvaria.org
nick = glossbot
rooms = ibugev@muc.vvvvvvaria.org, xbotlibtest@muc.vvvvvvaria.org

90
glossbot.xbotlib/glossbot.py

@ -0,0 +1,90 @@
from random import choice
from xbotlib import Bot
class GlossBot(Bot):
"""Building a shared glossary together.
A glossary is "an alphabetical list of terms in a particular domain of
knowledge with the definitions for those terms."
This bot reacts to commands which insert, list or delete items from a
shared glossary when summoned in a group chat. This bot makes use of
persistent storage so the glossary is always there even if the bot goes
away.
"""
help = """
I help build a shared glossary
glossbot: @add <entry> - <definition>
glossbot: @rm <entry>
glossbot: @rand
glossbot: @ls
"""
def group(self, message):
"""Handle glossary commands."""
if "@add" in message.content:
try:
parsed = self.parse_add(message)
self.add(*parsed, room=message.room)
except Exception:
response = f"Couldn't understand '{message.content}'?"
self.reply(response, room=message.sender)
elif "@rm" in message.content:
try:
parsed = message.content.split("@rm")[-1].strip()
self.rm(parsed, room=message.room)
except Exception:
response = f"Couldn't understand '{message.content}'?"
self.reply(response, room=message.sender)
elif "@rand" in message.content:
self.rand(room=message.room)
elif "@ls" in message.content:
self.ls(room=message.room)
else:
self.log.info(f"{message.text} not recognised as glossbot command")
def parse_add(self, message):
"""Parse the add command syntax."""
try:
replaced = message.content.replace("@add", "")
return [s.strip() for s in replaced.split("-", 1)]
except ValueError:
self.log.error(f"Failed to parse {message.content}")
def add(self, entry, definition, **kwargs):
"""Add a new entry."""
self.db[entry] = definition
self.reply("Added ✌️", **kwargs)
def rand(self, **kwargs):
"""List a random entry."""
if not self.db.keys():
self.reply("Glossary is empty 🙃️", **kwargs)
return
entry = choice(list(self.db.keys()))
self.reply(f"{entry} - {self.db[entry]}", **kwargs)
def ls(self, **kwargs):
"""List all entries."""
if not self.db.keys():
self.reply("Glossary is empty 🙃️", **kwargs)
return
for entry in sorted(self.db.keys()):
self.reply(f"{entry} - {self.db[entry]}", **kwargs)
def rm(self, entry, **kwargs):
"""Remove an entry."""
if entry not in self.db.keys():
self.reply(f"{entry} doesn't exist?", **kwargs)
return
self.db.pop(entry)
self.reply("Removed ✌️", **kwargs)
GlossBot()

BIN
logsbot/avatar.png

After

Width: 64  |  Height: 64  |  Size: 11 KiB

13
logsbot/index.html.j2

@ -0,0 +1,13 @@
<html>
<head>
</head>
<body>
<h1>logsbot collective log</h1>
{% for room in payload["rooms"] %}
<h2>{{ room }}</h2>
{% for url in payload[room]["urls"] %}
<img src="{{ url }}" />
{% endfor %}
{% endfor %}
</body>
</html>

4
logsbot/logsbot.conf

@ -0,0 +1,4 @@
[logsbot]
account = logsbot@vvvvvvaria.org
nick = logsbot
rooms = ibugev@muc.vvvvvvaria.org, xbotlibtest@muc.vvvvvvaria.org

37
logsbot/logsbot.py

@ -0,0 +1,37 @@
from os.path import basename
from urllib.parse import urlparse
from xbotlib import Bot
class LogsBot(Bot):
"""Collaborative log writing."""
help = """Logging to https://logsbot.bots.varia.zone"""
def group(self, message):
"""Move group messages into the log."""
if not message.url:
return
if message.room not in self.db.keys():
self.db[message.room] = []
self.db[message.room].append(message.url)
filename = basename(urlparse(message.url).path)
return self.reply(f"Added {filename} 🤩️", room=message.room)
def serve(self, request):
"""Serve the log."""
payload = {"rooms": []}
for room in self.db.keys():
payload["rooms"].append(room)
payload[room] = {"urls": self.db[room]}
rendered = self.template.render(payload=payload)
return self.respond(rendered)
LogsBot()

BIN
whisperbot.xbotlib/avatar.png

After

Width: 64  |  Height: 46  |  Size: 6.4 KiB

4
whisperbot.xbotlib/whisperbot.conf

@ -0,0 +1,4 @@
[whisperbot]
account = whisperbot@vvvvvvaria.org
nick = whisperbot
rooms = ibugev@muc.vvvvvvaria.org, xbotlibtest@muc.vvvvvvaria.org, members@muc.vvvvvvaria.org

21
whisperbot.xbotlib/whisperbot.py

@ -0,0 +1,21 @@
from xbotlib import Bot
class WhisperBot(Bot):
"""Anonymous whispering in group chats.
In order to activate this bot you can invite it to your group chat. Once
invited, you can start a private chat with the bot and tell it you want it
to whisper your message into the group chat. The bot will then do this on
your behalf and not reveal your identity. This is nice when you want to
communicate with the group anonymously.
"""
help = "I whisper private messages into group chats 😌️"
def direct(self, message):
"""Receive private messages and whisper them into group chats."""
self.reply(f"*pssttt...* {message.content}", room=message.room)
WhisperBot()
Loading…
Cancel
Save