Skip to content

Commit

Permalink
修改插件结构
Browse files Browse the repository at this point in the history
  • Loading branch information
baimianxiao committed Feb 12, 2024
1 parent 9277c95 commit 62314c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
7 changes: 5 additions & 2 deletions GuDice/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# -*- encoding:utf-8 -*-

from GuDice.api import API
from GuDice.bot import Bot
from GuDice.classify import Classify
from GuDice.dice import Dice
from GuDice.event import Event
from GuDice.plugin import PluginManager
from GuDice.plugin import PluginManager, Plugin

__all__ = [
"API",
"Classify",
"Dice",
"Event",
"PluginManager"
"PluginManager",
"Plugin"
]
11 changes: 2 additions & 9 deletions GuDice/event.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
# -*- encoding:utf-8 -*-

class Event:

def private_message(self, event, bot):
def private_message(self, data, bot):
pass

def group_message(self, event, bot):
def group_message(self, data, bot):
pass

def main(self, event, bot):
if event['type'] == "private_message":
self.private_message(event['data'], bot)
elif event['type'] == "group_message":
self.group_message(event['data'], bot)


class MessageData:
user_id: int
Expand Down
13 changes: 13 additions & 0 deletions GuDice/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import importlib
from os.path import abspath, join, exists, dirname
from GuDice import Event, API

file_dir = dirname(abspath(__file__))

Expand Down Expand Up @@ -35,6 +36,18 @@ def plugin_test(self):
pass


# 插件基类
class Plugin(Event):
def init(self):
pass

def main(self, event, bot):
if event['type'] == "private_message":
self.private_message(event['data'], bot)
elif event['type'] == "group_message":
self.group_message(event['data'], bot)


if __name__ == "__main__":
Manager = PluginManager()
Manager.plugin_registered()
Expand Down

0 comments on commit 62314c3

Please sign in to comment.