1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| import os import json from urllib.parse import quote
class Plugin(object): plugin_methods={'register':{'priority':30000,'func':'register','desc':'注册插件'},'enable':{'priority':30000,'func':'enable','desc':'启用插件'},'disable':{'priority':30000,'func':'disable','desc':'禁用插件'},'unregister':{'priority':30000,'func':'unregister','desc':'卸载插件'},'group_message':{'priority':30000,'func':'group_message','desc':'群消息处理'}} plugin_commands={'shenmeme':'shenmeme_command','help':'shenmeme enable <群号> - 在指定群启用\nshenmeme disable <群号> - 在指定群禁用'} plugin_auths={'send_group_msg','get_group_member_info','get_stranger_info'} auth='' log=None bot=None util=None dir=None config={'group':[]}
def register(self,logger,util,bot,dir): self.log=logger self.bot=bot self.util=util self.dir=dir self.log.info("Plugin register")
def enable(self,auth): self.auth=auth try: with open(os.path.join(self.dir,'config.json'),'r') as f: self.config=json.loads(f.read()) except: with open(os.path.join(self.dir,'config.json'),'w') as f: f.write(json.dumps(self.config)) self.log.info("Plugin enable")
def disable(self): try: with open(os.path.join(self.dir,'config.json'),'w') as f: f.write(json.dumps(self.config)) except: pass self.log.info("Plugin disable")
def unregister(self): self.log.info("Plugin unregister")
def group_message(self,time,self_id,sub_type,message_id,group_id,user_id,anonymous,message,raw_message,font,sender): if group_id in self.config['group']: if raw_message.startswith('神') and len(raw_message)>6: qq=0 try: qq=int(raw_message[1:].strip()) except: qq=0 for m in message: if m['type']=='at': try: qq=int(m['data']['qq']) except: qq=0 if qq==0: return False nickname='' status,res=self.util.get_group_member_info(self.auth,group_id,qq,no_cache=True) if status: nickname=res.get('nickname','') if nickname=='': status,res=self.util.get_stranger_info(self.auth,qq) if status: nickname=res.get('nickname','') if nickname=='': nickname=str(qq) self.util.send_group_msg(self.auth,group_id,self.util.seg_image('http://47.105.107.105:8000/meme?qq='+str(qq)+'&name='+quote(nickname))) return True return False
def shenmeme_command(self,cmd): if len(cmd)==2: if cmd[0]=='enable': try: if int(cmd[1]) not in self.config['group']: self.config['group'].append(int(cmd[1])) with open(os.path.join(self.dir,'config.json'),'w') as f: f.write(json.dumps(self.config)) self.log.info('启用成功') except: self.log.warning('参数错误') elif cmd[0]=='disable': try: if int(cmd[1]) in self.config['group']: self.config['group'].remove(int(cmd[1])) with open(os.path.join(self.dir,'config.json'),'w') as f: f.write(json.dumps(self.config)) self.log.info('禁用成功') except: self.log.warning('参数错误') else: self.log.warning('参数错误')
plugin_name="FengZi的神meme" plugin_id="tk.mcsog.fengzi_shenmeme" plugin_version="1.0.0" plugin_author="f00001111" plugin_desc="FengZi的神meme插件适配"
|