You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1 年之前
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # encoding:utf-8
  2. import plugins
  3. from bridge.context import ContextType
  4. from bridge.reply import Reply, ReplyType
  5. from channel.chat_message import ChatMessage
  6. from common.log import logger
  7. from plugins import *
  8. from config import conf
  9. @plugins.register(
  10. name="Hello",
  11. desire_priority=-1,
  12. hidden=True,
  13. desc="A simple plugin that says hello",
  14. version="0.1",
  15. author="lanvent",
  16. )
  17. class Hello(Plugin):
  18. def __init__(self):
  19. super().__init__()
  20. self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context
  21. logger.info("[Hello] inited")
  22. def on_handle_context(self, e_context: EventContext):
  23. if e_context["context"].type not in [
  24. ContextType.TEXT,
  25. ContextType.JOIN_GROUP,
  26. ContextType.PATPAT,
  27. ]:
  28. return
  29. if e_context["context"].type == ContextType.JOIN_GROUP:
  30. if "group_welcome_msg" in conf():
  31. reply = Reply()
  32. reply.type = ReplyType.TEXT
  33. reply.content = conf().get("group_welcome_msg", "")
  34. e_context["reply"] = reply
  35. e_context.action = EventAction.BREAK_PASS # 事件结束,并跳过处理context的默认逻辑
  36. return
  37. e_context["context"].type = ContextType.TEXT
  38. msg: ChatMessage = e_context["context"]["msg"]
  39. e_context["context"].content = f'请你随机使用一种风格说一句问候语来欢迎新用户"{msg.actual_user_nickname}"加入群聊。'
  40. e_context.action = EventAction.BREAK # 事件结束,进入默认处理逻辑
  41. return
  42. if e_context["context"].type == ContextType.PATPAT:
  43. e_context["context"].type = ContextType.TEXT
  44. msg: ChatMessage = e_context["context"]["msg"]
  45. e_context["context"].content = f"请你随机使用一种风格介绍你自己,并告诉用户输入#help可以查看帮助信息。"
  46. e_context.action = EventAction.BREAK # 事件结束,进入默认处理逻辑
  47. return
  48. content = e_context["context"].content
  49. logger.debug("[Hello] on_handle_context. content: %s" % content)
  50. if content == "Hello":
  51. reply = Reply()
  52. reply.type = ReplyType.TEXT
  53. msg: ChatMessage = e_context["context"]["msg"]
  54. if e_context["context"]["isgroup"]:
  55. reply.content = f"Hello, {msg.actual_user_nickname} from {msg.from_user_nickname}"
  56. else:
  57. reply.content = f"Hello, {msg.from_user_nickname}"
  58. e_context["reply"] = reply
  59. e_context.action = EventAction.BREAK_PASS # 事件结束,并跳过处理context的默认逻辑
  60. if content == "Hi":
  61. reply = Reply()
  62. reply.type = ReplyType.TEXT
  63. reply.content = "Hi"
  64. e_context["reply"] = reply
  65. e_context.action = EventAction.BREAK # 事件结束,进入默认处理逻辑,一般会覆写reply
  66. if content == "End":
  67. # 如果是文本消息"End",将请求转换成"IMAGE_CREATE",并将content设置为"The World"
  68. e_context["context"].type = ContextType.IMAGE_CREATE
  69. content = "The World"
  70. e_context.action = EventAction.CONTINUE # 事件继续,交付给下个插件或默认逻辑
  71. def get_help_text(self, **kwargs):
  72. help_text = "输入Hello,我会回复你的名字\n输入End,我会回复你世界的图片\n"
  73. return help_text