Initial commit
This commit is contained in:
commit
250df44778
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
env/
|
||||||
|
.vscode/
|
||||||
|
__pycache__/
|
||||||
103
main.py
Normal file
103
main.py
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import importlib
|
||||||
|
from pathlib import Path
|
||||||
|
from pprint import pprint
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import random
|
||||||
|
|
||||||
|
# List of loaded plugins
|
||||||
|
loadedPlugins = []
|
||||||
|
|
||||||
|
# Temp lists to store plugin info
|
||||||
|
tmpgenericHooks = []
|
||||||
|
tmpmessageHooks = []
|
||||||
|
tmpmentionHooks = []
|
||||||
|
|
||||||
|
# List of functions per hook
|
||||||
|
|
||||||
|
genericHooks = []
|
||||||
|
messageHooks = []
|
||||||
|
mentionHooks = []
|
||||||
|
|
||||||
|
messages = [{"name":"1","message":"message1"}, {"name":"2","message":"message2"}, {"name":"3","message":"Hey @ben sup"}, {"name":"test","message":"Hello World"},{"name":"Ben","message":"@1 sup"}]
|
||||||
|
|
||||||
|
def registerGenericHooks():
|
||||||
|
# Run this to run the registered hooks in a plugin
|
||||||
|
for x in tmpgenericHooks:
|
||||||
|
for y in x[1]:
|
||||||
|
genericHooks.append(getattr(sys.modules[f"{x[0]}"], f"{y}"))
|
||||||
|
|
||||||
|
|
||||||
|
def registerMessageHooks():
|
||||||
|
# Run this to run the registered hooks in a plugin
|
||||||
|
for x in tmpmessageHooks:
|
||||||
|
for y in x[1]:
|
||||||
|
messageHooks.append(getattr(sys.modules[f"{x[0]}"], f"{y}"))
|
||||||
|
|
||||||
|
|
||||||
|
def registerMentionHooks():
|
||||||
|
# Run this to run the registered hooks in a plugin
|
||||||
|
for x in tmpmentionHooks:
|
||||||
|
for y in x[1]:
|
||||||
|
mentionHooks.append(getattr(sys.modules[f"{x[0]}"], f"{y}"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def buildHookList():
|
||||||
|
# Buld Generic hook lists
|
||||||
|
for x in loadedPlugins:
|
||||||
|
try:
|
||||||
|
tmpgenericHooks.append(x.genericHooks())
|
||||||
|
tmpmessageHooks.append(x.messageHooks())
|
||||||
|
tmpmentionHooks.append(x.mentionHooks())
|
||||||
|
except AttributeError as e:
|
||||||
|
print(f"{e}")
|
||||||
|
|
||||||
|
# pprint(loadedPlugins)
|
||||||
|
|
||||||
|
def loadPlugins():
|
||||||
|
p = Path("plugins/")
|
||||||
|
files = [x for x in p.iterdir() if x.suffix == ".py"]
|
||||||
|
|
||||||
|
for x in files:
|
||||||
|
mod = x.stem
|
||||||
|
loadedPlugins.append(importlib.import_module(f"plugins.{mod}"))
|
||||||
|
for x in loadedPlugins:
|
||||||
|
try:
|
||||||
|
x.pluginStart()
|
||||||
|
except AttributeError:
|
||||||
|
print(f"{x.__name__} failed to load as there is no pluginStart method")
|
||||||
|
|
||||||
|
def runGenericHooks():
|
||||||
|
for x in genericHooks:
|
||||||
|
x()
|
||||||
|
|
||||||
|
def runMessageHooks(msg):
|
||||||
|
for x in messageHooks:
|
||||||
|
x(msg)
|
||||||
|
|
||||||
|
def runMentionHooks(msg):
|
||||||
|
for x in mentionHooks:
|
||||||
|
x(msg)
|
||||||
|
|
||||||
|
def init():
|
||||||
|
loadPlugins()
|
||||||
|
buildHookList()
|
||||||
|
registerGenericHooks()
|
||||||
|
registerMessageHooks()
|
||||||
|
registerMentionHooks()
|
||||||
|
|
||||||
|
# pprint(hooks)
|
||||||
|
|
||||||
|
init()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
runGenericHooks()
|
||||||
|
msg = random.choice(messages)
|
||||||
|
runMessageHooks(msg)
|
||||||
|
if "@" in msg['message']:
|
||||||
|
print("running mentions")
|
||||||
|
runMentionHooks(msg)
|
||||||
|
time.sleep(1)
|
||||||
29
plugin_example.py
Normal file
29
plugin_example.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
def pluginStart():
|
||||||
|
print(f"Starting '{__name__}'")
|
||||||
|
|
||||||
|
def genericHooks():
|
||||||
|
print(f"Starting '{__name__}'")
|
||||||
|
funcList = ["exampleFunc"]
|
||||||
|
print(f"Registering hooks {funcList}")
|
||||||
|
return [__name__,funcList]
|
||||||
|
|
||||||
|
def messageHooks():
|
||||||
|
funcList = ["onMessage"]
|
||||||
|
print(f"Registering hooks {funcList}")
|
||||||
|
return [__name__,funcList]
|
||||||
|
|
||||||
|
def mentionHooks():
|
||||||
|
funcList = ["onMention"]
|
||||||
|
return [__name__,funcList]
|
||||||
|
|
||||||
|
def exampleFunc():
|
||||||
|
# Do code
|
||||||
|
pass
|
||||||
|
|
||||||
|
def onMessage(msg):
|
||||||
|
# Do code
|
||||||
|
pass
|
||||||
|
|
||||||
|
def onMention(msg):
|
||||||
|
# Do code
|
||||||
|
pass
|
||||||
1
plugins/.gitignore
vendored
Normal file
1
plugins/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
__pycache__/
|
||||||
31
plugins/1.py
Normal file
31
plugins/1.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
def pluginStart():
|
||||||
|
print(f"Starting '{__name__}'")
|
||||||
|
|
||||||
|
def genericHooks():
|
||||||
|
print(f"Starting '{__name__}'")
|
||||||
|
funcList = ["test1"]
|
||||||
|
print(f"Registering hooks {funcList}")
|
||||||
|
return [__name__,funcList]
|
||||||
|
|
||||||
|
def messageHooks():
|
||||||
|
funcList = ["onMessage"]
|
||||||
|
print(f"Registering hooks {funcList}")
|
||||||
|
return [__name__,funcList]
|
||||||
|
|
||||||
|
def mentionHooks():
|
||||||
|
funcList = ["onMention"]
|
||||||
|
return [__name__,funcList]
|
||||||
|
|
||||||
|
def test1():
|
||||||
|
internalFunc("test")
|
||||||
|
|
||||||
|
def internalFunc(name):
|
||||||
|
print(f"Looks like this works running from: {name}")
|
||||||
|
|
||||||
|
def onMessage(msg):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def onMention(msg):
|
||||||
|
pass
|
||||||
19
plugins/2.py
Normal file
19
plugins/2.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
def pluginStart():
|
||||||
|
print(f"Starting '{__name__}'")
|
||||||
|
|
||||||
|
|
||||||
|
def genericHooks():
|
||||||
|
print(f"Starting '{__name__}'")
|
||||||
|
funcList = ["memes1"]
|
||||||
|
print(f"Registering hooks {funcList}")
|
||||||
|
return [__name__,funcList]
|
||||||
|
|
||||||
|
def messageHooks():
|
||||||
|
funcList = ["onMessage"]
|
||||||
|
return [__name__,funcList]
|
||||||
|
|
||||||
|
def memes1():
|
||||||
|
return "memes"
|
||||||
|
|
||||||
|
def onMessage(msg):
|
||||||
|
print(f"Hey {msg['name']}, called from {__name__}")
|
||||||
23
plugins/3.py
Normal file
23
plugins/3.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
def pluginStart():
|
||||||
|
print(f"Starting '{__name__}'")
|
||||||
|
|
||||||
|
def genericHooks():
|
||||||
|
print(f"Starting '{__name__}'")
|
||||||
|
funcList = ["test11"]
|
||||||
|
print(f"Registering hooks {funcList}")
|
||||||
|
return [__name__,funcList]
|
||||||
|
|
||||||
|
def messageHooks():
|
||||||
|
funcList = ["onMessage"]
|
||||||
|
print(f"Registering hooks {funcList}")
|
||||||
|
return [__name__,funcList]
|
||||||
|
|
||||||
|
def test11():
|
||||||
|
print("test11")
|
||||||
|
|
||||||
|
def onMessage(msg):
|
||||||
|
if msg['name'] == "test":
|
||||||
|
print("Return test!")
|
||||||
|
return "Test was here"
|
||||||
0
plugins/4.py
Normal file
0
plugins/4.py
Normal file
31
plugins/chat.py
Normal file
31
plugins/chat.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
def pluginStart():
|
||||||
|
print(f"Starting '{__name__}'")
|
||||||
|
|
||||||
|
def genericHooks():
|
||||||
|
print(f"Starting '{__name__}'")
|
||||||
|
funcList = []
|
||||||
|
print(f"Registering hooks {funcList}")
|
||||||
|
return [__name__,funcList]
|
||||||
|
|
||||||
|
def messageHooks():
|
||||||
|
funcList = ["onMessage"]
|
||||||
|
print(f"Registering hooks {funcList}")
|
||||||
|
return [__name__,funcList]
|
||||||
|
|
||||||
|
def mentionHooks():
|
||||||
|
funcList = ["onMention"]
|
||||||
|
return [__name__,funcList]
|
||||||
|
|
||||||
|
def exampleFunc():
|
||||||
|
# Do code
|
||||||
|
pass
|
||||||
|
|
||||||
|
def onMessage(msg):
|
||||||
|
print(f"From: {msg['name']}\nMessage: {msg['message']}")
|
||||||
|
|
||||||
|
def onMention(msg):
|
||||||
|
mention = re.search(r"@.+? ", msg["message"]).group(0)
|
||||||
|
mention = mention.strip()
|
||||||
|
print(f"{mention.split('@')[1]} got mentioned")
|
||||||
Loading…
x
Reference in New Issue
Block a user