update
This commit is contained in:
parent
b774e0d04c
commit
ad4ec4d3a9
12
glados.py
12
glados.py
@ -7,6 +7,8 @@ from matrix_client.api import MatrixRequestError
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from plugins.plugin_manager import PluginManager
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
config = __import__(sys.argv[1])
|
config = __import__(sys.argv[1])
|
||||||
else:
|
else:
|
||||||
@ -14,9 +16,11 @@ else:
|
|||||||
|
|
||||||
class Bot:
|
class Bot:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.client = MatrixClient(config.BOT_SERVER)
|
self.client = MatrixClient(config.BOT_SERVER, config.BOT_TOKEN)
|
||||||
try:
|
try:
|
||||||
self.client.login_with_password(config.BOT_USERNAME, config.BOT_PASSWORD)
|
if not config.BOT_TOKEN:
|
||||||
|
self.client.login(config.BOT_USERNAME, config.BOT_PASSWORD)
|
||||||
|
print(self.client.token)
|
||||||
except MatrixRequestError as e:
|
except MatrixRequestError as e:
|
||||||
print(e)
|
print(e)
|
||||||
if e.code == 403:
|
if e.code == 403:
|
||||||
@ -24,6 +28,9 @@ class Bot:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
self.plugin_manager = PluginManager(self, config)
|
self.plugin_manager = PluginManager(self, config)
|
||||||
|
for plugin in ['help', 'say', 'admin', 'free_games']:
|
||||||
|
self.plugin_manager.load_plugin(plugin)
|
||||||
|
|
||||||
self.rooms = {}
|
self.rooms = {}
|
||||||
for room_id, room_data in config.rooms.items():
|
for room_id, room_data in config.rooms.items():
|
||||||
self.rooms[room_id] = self.client.join_room(room_id)
|
self.rooms[room_id] = self.client.join_room(room_id)
|
||||||
@ -33,6 +40,7 @@ class Bot:
|
|||||||
self.client.start_listener_thread()
|
self.client.start_listener_thread()
|
||||||
#return client.sync_thread
|
#return client.sync_thread
|
||||||
|
|
||||||
|
print("Bot ready, listening...")
|
||||||
while True:
|
while True:
|
||||||
input()
|
input()
|
||||||
|
|
||||||
|
BIN
plugins/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
plugins/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
plugins/__pycache__/admin.cpython-310.pyc
Normal file
BIN
plugins/__pycache__/admin.cpython-310.pyc
Normal file
Binary file not shown.
BIN
plugins/__pycache__/free_games.cpython-310.pyc
Normal file
BIN
plugins/__pycache__/free_games.cpython-310.pyc
Normal file
Binary file not shown.
BIN
plugins/__pycache__/help.cpython-310.pyc
Normal file
BIN
plugins/__pycache__/help.cpython-310.pyc
Normal file
Binary file not shown.
BIN
plugins/__pycache__/plugin.cpython-310.pyc
Normal file
BIN
plugins/__pycache__/plugin.cpython-310.pyc
Normal file
Binary file not shown.
BIN
plugins/__pycache__/plugin_manager.cpython-310.pyc
Normal file
BIN
plugins/__pycache__/plugin_manager.cpython-310.pyc
Normal file
Binary file not shown.
BIN
plugins/__pycache__/say.cpython-310.pyc
Normal file
BIN
plugins/__pycache__/say.cpython-310.pyc
Normal file
Binary file not shown.
@ -12,12 +12,12 @@ class Admin(Plugin):
|
|||||||
super(Admin, self).deactivate()
|
super(Admin, self).deactivate()
|
||||||
|
|
||||||
@Plugin.command(admin=True)
|
@Plugin.command(admin=True)
|
||||||
def admin_reload_plugins(self, msg, args):
|
def admin_reload_plugins(self, room, event, args):
|
||||||
"""Reload plugins"""
|
"""Reload plugins"""
|
||||||
self.plugin_manager.reload_plugins()
|
self.plugin_manager.reload_plugins()
|
||||||
return "Plugins reloaded"
|
return "Plugins reloaded"
|
||||||
|
|
||||||
@Plugin.command(admin=True)
|
@Plugin.command(admin=True)
|
||||||
def admin_test(self, msg, args):
|
def admin_test(self, room, event, args):
|
||||||
"""Simple test"""
|
"""Simple test"""
|
||||||
return "You are admin"
|
return "You are admin"
|
||||||
|
30
plugins/free_games.py
Normal file
30
plugins/free_games.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from plugins.plugin import Plugin
|
||||||
|
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
class FreeGames(Plugin):
|
||||||
|
def activate(self):
|
||||||
|
super(FreeGames, self).activate()
|
||||||
|
|
||||||
|
def deactivate(self):
|
||||||
|
super(FreeGames, self).deactivate()
|
||||||
|
|
||||||
|
@Plugin.command()
|
||||||
|
def epic(self, room, event, args):
|
||||||
|
"""Display Epic free games => !epic"""
|
||||||
|
r=requests.get('https://feed.phenx.de/lootscraper_epic_game.xml')
|
||||||
|
soup = BeautifulSoup(r.content, 'xml')
|
||||||
|
c_list = soup.find_all('entry')
|
||||||
|
for c in c_list:
|
||||||
|
link = c.find('link').get('href')
|
||||||
|
title = c.find('title')
|
||||||
|
content = "{}\n".format(title.text)
|
||||||
|
content = "{}\n\n".format(link)
|
||||||
|
for li in c.find_all('li'):
|
||||||
|
content += "- {}\n".format(li.text)
|
||||||
|
room.send_text(content)
|
||||||
|
|
@ -25,7 +25,7 @@ class Help(Plugin):
|
|||||||
reply = ['Usage:']
|
reply = ['Usage:']
|
||||||
for command_name in command_names:
|
for command_name in command_names:
|
||||||
command = self.plugin_manager.commands[command_name]
|
command = self.plugin_manager.commands[command_name]
|
||||||
if not self.plugin_manager.is_admin_command(command_name) or self.plugin_manager.is_sender_admin(msg):
|
if not self.plugin_manager.is_admin_command(command_name) or self.plugin_manager.is_sender_admin(event):
|
||||||
reply.append('{0}: {1}'.format(command_name, command['function'].__doc__ or 'N/A'))
|
reply.append('{0}: {1}'.format(command_name, command['function'].__doc__ or 'N/A'))
|
||||||
room.send_text("\n".join(reply))
|
room.send_text("\n".join(reply))
|
||||||
return True
|
return True
|
||||||
|
@ -86,16 +86,7 @@ class PluginManager:
|
|||||||
room.send_text(reply)
|
room.send_text(reply)
|
||||||
|
|
||||||
def is_sender_admin(self, event):
|
def is_sender_admin(self, event):
|
||||||
return False
|
return event['sender'] in self.config.ADMINS
|
||||||
"""Checks if author is admin"""
|
|
||||||
if message['type'] == 'groupchat':
|
|
||||||
# We don't know the jid. Either there's a problem or it's an anonymous room
|
|
||||||
if message['from'].full not in self.bot.presences:
|
|
||||||
return False
|
|
||||||
jid = self.bot.presences[message['from'].full]
|
|
||||||
else:
|
|
||||||
jid = message['from'].full.split('/')[0]
|
|
||||||
return jid in self.config.ADMINS
|
|
||||||
|
|
||||||
def is_admin_command(self, command):
|
def is_admin_command(self, command):
|
||||||
return command in self.commands and self.commands[command]['options'].get('admin', False)
|
return command in self.commands and self.commands[command]['options'].get('admin', False)
|
||||||
|
9
requirements.txt
Normal file
9
requirements.txt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
beautifulsoup4==4.12.3
|
||||||
|
certifi==2024.8.30
|
||||||
|
charset-normalizer==3.4.0
|
||||||
|
idna==3.10
|
||||||
|
lxml==5.3.0
|
||||||
|
matrix-client==0.4.0
|
||||||
|
requests==2.32.3
|
||||||
|
soupsieve==2.6
|
||||||
|
urllib3==1.26.20
|
Loading…
x
Reference in New Issue
Block a user