Allen 1 hónapja
szülő
commit
c366fd12e2
3 módosított fájl, 24 hozzáadás és 14 törlés
  1. 11 2
      README.md
  2. 6 6
      config.py
  3. 7 6
      owncastcom.py

+ 11 - 2
README.md

@@ -1,3 +1,12 @@
-# Owncastcom
+### Owncastcom
 
-An XMPP bot for sending messages to Owncast chat, from your XMPP account.
+An XMPP bot for sending messages to Owncast chat, from your XMPP account.
+
+### Config file
+``` log_file = ''  # /path/to/log.log
+    user = ''  # The bot's XMPP account username
+    passwd = ''  # The bot's XMPP account password
+    auth_bearer = ''  # The bot's Owncast API token
+    api_url = 'http://'  # Your Owncast API url
+    approved_senders = []  # The list of XMPP accounts allowed to send messages to the bot
+```

+ 6 - 6
config.py

@@ -1,6 +1,6 @@
-log_file = ''
-user = ''  # The bot's XMPP account username
-passwd = ''  # The bot's XMPP account password
-auth_bearer = ''  # The bot's Owncast API token
-api_url = 'http://'  # Your Owncast API url
-approved_senders = []  # The list of XMPP accounts allowed to send messages to the bot
+log_file = '/home/deadtom/logs/owncastcom.log'
+user = 'owncast@deadtom.me'
+passwd = 'xYNOPNhYcPrFyF995joNCom1'
+auth_bearer = 'Bearer 2VajnuURArN0k6XAPLF9P8tFTFGbQpr8TP7Uq5CrtiI='
+api_url = 'http://owncast-actual:8083'
+approved_senders = ['deadtom@deadtom.me',]

+ 7 - 6
owncastcom.py

@@ -1,3 +1,5 @@
+#!/home/deadtom/python/.xmpp-venv/bin/python
+
 import config
 import logging
 from slixmpp import ClientXMPP
@@ -6,17 +8,16 @@ import requests
 import json
 import sys
 import os
-import asyncio
 
 logging.basicConfig(filename=config.log_file, level=logging.INFO)
 
 
-def get_now():  # This creates a timestamp for the log
+def get_now():  # This creates and returns a time stamp
     now = str(time.strftime("%Y/%m/%d %H:%M:%S"))
     return now
 
 
-def send_ownchat(msg):  # Sends the message to Owncast chat
+def send_ownchat(msg):
     msg_body = {'body': msg}
     headers = {'Authorization': config.auth_bearer}
     response = requests.post(f'{config.api_url}/api/integrations/chat/send', data=json.dumps(msg_body),
@@ -24,7 +25,7 @@ def send_ownchat(msg):  # Sends the message to Owncast chat
     return response.json()
 
 
-class CommandBot(ClientXMPP):  # The XMPP bot
+class CommandBot(ClientXMPP):
 
     def __init__(self, jid, password):
         ClientXMPP.__init__(self, jid, password)
@@ -46,7 +47,7 @@ class CommandBot(ClientXMPP):  # The XMPP bot
         if msg['type'] in ('chat', 'normal'):
             self.msg = msg
             self.cmd = self.msg['body']  # Get the body out of the message
-            self.cmd = self.cmd.lower()
+            self.cmd = self.cmd.lower()  # Convert it to lower case to avoid problems looking up available commands
             self.sender = self.msg['from']  # Get sender
             self.sender = str(self.sender)  # Convert to string so split() can work with it
             self.sender = self.sender.split('/')[0]  # Only save the information before the forward slash
@@ -64,7 +65,7 @@ try:
     if __name__ == '__main__':
         xmpp = CommandBot(config.user, config.passwd)
         xmpp.connect()
-        asyncio.get_event_loop().run_forever()
+        xmpp.process(forever=True)
 except KeyboardInterrupt:  # Catch ctrl-alt-del
     print('\nExiting program...')
     sys.exit()