Skip to content

Commit

Permalink
用户记录优化
Browse files Browse the repository at this point in the history
  • Loading branch information
lunzhiPenxil committed Jan 6, 2022
1 parent 5ae785b commit fb8917a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 19 deletions.
3 changes: 3 additions & 0 deletions OlivaDiceLogger/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"author" : "lunzhiPenxil",
"namespace" : "OlivaDiceLogger",
"message_mode" : "old_string",
"version" : "3.0.2",
"svn" : 10,
"compatible_svn" : 81,
"priority" : 30030,
"support" : [
{
Expand Down
4 changes: 3 additions & 1 deletion OlivaDiceLogger/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
'''


OlivaDiceLogger_ver = '3.0.0'
OlivaDiceLogger_ver = '3.0.2'
OlivaDiceLogger_svn = 10
OlivaDiceLogger_ver_short = '%s(%s)' % (str(OlivaDiceLogger_ver), str(OlivaDiceLogger_svn))

dataPath = './plugin/data/OlivaDice/unity'
dataLogPath = '/logger'
Expand Down
9 changes: 7 additions & 2 deletions OlivaDiceLogger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def logger_func(*arg, **kwargs):

def loggerEntry(event, funcType, sender, dectData, message):
[host_id, group_id, user_id] = dectData
tmp_hagID = None
if host_id != None and group_id != None:
tmp_hagID = '%s|%s' % (str(host_id), str(group_id))
elif group_id != None:
tmp_hagID = str(group_id)
tmp_name = 'N/A'
tmp_id = -1
if 'name' in sender:
Expand All @@ -51,7 +56,7 @@ def loggerEntry(event, funcType, sender, dectData, message):
'send_group'
]:
if OlivaDiceCore.userConfig.getUserConfigByKey(
userId = group_id,
userId = tmp_hagID,
userType = 'group',
platform = event.platform['platform'],
userConfigKey = 'logEnable',
Expand All @@ -73,7 +78,7 @@ def loggerEntry(event, funcType, sender, dectData, message):
}
log_str = json.dumps(log_dict, ensure_ascii = False)
tmp_logName = OlivaDiceCore.userConfig.getUserConfigByKey(
userId = group_id,
userId = tmp_hagID,
userType = 'group',
platform = event.platform['platform'],
userConfigKey = 'logNowName',
Expand Down
2 changes: 1 addition & 1 deletion OlivaDiceLogger/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def init(plugin_event, Proc):
OlivaDiceLogger.msgReply.unity_init(plugin_event, Proc)

def init_after(plugin_event, Proc):
OlivaDiceCore.crossHook.dictHookList['model'].append(['OlivaDiceLogger', OlivaDiceLogger.data.OlivaDiceLogger_ver])
OlivaDiceCore.crossHook.dictHookList['model'].append(['OlivaDiceLogger', OlivaDiceLogger.data.OlivaDiceLogger_ver_short])
OlivaDiceLogger.logger.init_logger(plugin_event, Proc)
OlivaDiceLogger.msgReply.data_init(plugin_event, Proc)

Expand Down
11 changes: 11 additions & 0 deletions OlivaDiceLogger/msgCustom.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,16 @@
.log end 完成记录并发送日志文件
日志上传存在失败可能,届时请联系后台管理索取''',

'OlivaDiceLogger': '''[OlivaDiceLogger]
OlivaDice日志模块
本模块为青果跑团掷骰机器人(OlivaDice)跑团日志模块,集成与跑团相关的跑团日志记录功能。
核心开发者: lunzhiPenxil仑质
[.help OlivaDiceLogger更新] 查看本模块更新日志
注: 本模块为可选重要模块。''',

'OlivaDiceLogger更新': '''[OlivaDiceLogger]
3.0.2: 用户记录优化
3.0.0: 初始化项目''',

'日志': '&log'
}
38 changes: 23 additions & 15 deletions OlivaDiceLogger/msgReply.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,25 @@ def unity_reply(plugin_event, Proc):
OlivaDiceCore.crossHook.dictHookList['prefix']
)
if flag_is_command:
tmp_hagID = None
if plugin_event.plugin_info['func_type'] == 'group_message':
if plugin_event.data.host_id != None:
flag_is_from_host = True
flag_is_from_group = True
elif plugin_event.plugin_info['func_type'] == 'private_message':
flag_is_from_group = False
if flag_is_from_host and flag_is_from_group:
tmp_hagID = '%s|%s' % (str(plugin_event.data.host_id), str(plugin_event.data.group_id))
elif flag_is_from_group:
tmp_hagID = str(plugin_event.data.group_id)
if flag_is_from_group:
if 'role' in plugin_event.data.sender:
flag_is_from_group_have_admin = True
if plugin_event.data.sender['role'] in ['owner', 'admin']:
flag_is_from_group_admin = True
elif plugin_event.data.sender['role'] in ['sub_admin']:
flag_is_from_group_admin = True
flag_is_from_group_sub_admin = True
flag_hostEnable = True
if flag_is_from_host:
flag_hostEnable = OlivaDiceCore.userConfig.getUserConfigByKey(
Expand All @@ -116,23 +124,23 @@ def unity_reply(plugin_event, Proc):
if flag_is_from_host:
if flag_hostEnable:
flag_groupEnable = OlivaDiceCore.userConfig.getUserConfigByKey(
userId = plugin_event.data.group_id,
userId = tmp_hagID,
userType = 'group',
platform = plugin_event.platform['platform'],
userConfigKey = 'groupEnable',
botHash = plugin_event.bot_info.hash
)
else:
flag_groupEnable = OlivaDiceCore.userConfig.getUserConfigByKey(
userId = plugin_event.data.group_id,
userId = tmp_hagID,
userType = 'group',
platform = plugin_event.platform['platform'],
userConfigKey = 'groupWithHostEnable',
botHash = plugin_event.bot_info.hash
)
else:
flag_groupEnable = OlivaDiceCore.userConfig.getUserConfigByKey(
userId = plugin_event.data.group_id,
userId = tmp_hagID,
userType = 'group',
platform = plugin_event.platform['platform'],
userConfigKey = 'groupEnable',
Expand All @@ -152,7 +160,7 @@ def unity_reply(plugin_event, Proc):
tmp_reast_str = getMatchWordStartRight(tmp_reast_str, 'on')
tmp_reast_str = skipSpaceStart(tmp_reast_str)
if not OlivaDiceCore.userConfig.getUserConfigByKey(
userId = plugin_event.data.group_id,
userId = tmp_hagID,
userType = 'group',
platform = plugin_event.platform['platform'],
userConfigKey = 'logEnable',
Expand All @@ -162,12 +170,12 @@ def unity_reply(plugin_event, Proc):
userConfigKey = 'logEnable',
userConfigValue = True,
botHash = plugin_event.bot_info.hash,
userId = plugin_event.data.group_id,
userId = tmp_hagID,
userType = 'group',
platform = plugin_event.platform['platform']
)
if OlivaDiceCore.userConfig.getUserConfigByKey(
userId = plugin_event.data.group_id,
userId = tmp_hagID,
userType = 'group',
platform = plugin_event.platform['platform'],
userConfigKey = 'logNowName',
Expand All @@ -178,7 +186,7 @@ def unity_reply(plugin_event, Proc):
userConfigKey = 'logNowName',
userConfigValue = tmp_new_logName,
botHash = plugin_event.bot_info.hash,
userId = plugin_event.data.group_id,
userId = tmp_hagID,
userType = 'group',
platform = plugin_event.platform['platform']
)
Expand All @@ -189,7 +197,7 @@ def unity_reply(plugin_event, Proc):
tmp_reply_str = dictStrCustom['strLoggerLogAlreadyOn'].format(**dictTValue)
OlivaDiceCore.userConfig.writeUserConfigByUserHash(
userHash = OlivaDiceCore.userConfig.getUserHash(
userId = plugin_event.data.group_id,
userId = tmp_hagID,
userType = 'group',
platform = plugin_event.platform['platform']
)
Expand All @@ -200,7 +208,7 @@ def unity_reply(plugin_event, Proc):
tmp_reast_str = getMatchWordStartRight(tmp_reast_str, 'off')
tmp_reast_str = skipSpaceStart(tmp_reast_str)
if OlivaDiceCore.userConfig.getUserConfigByKey(
userId = plugin_event.data.group_id,
userId = tmp_hagID,
userType = 'group',
platform = plugin_event.platform['platform'],
userConfigKey = 'logEnable',
Expand All @@ -210,7 +218,7 @@ def unity_reply(plugin_event, Proc):
userConfigKey = 'logEnable',
userConfigValue = False,
botHash = plugin_event.bot_info.hash,
userId = plugin_event.data.group_id,
userId = tmp_hagID,
userType = 'group',
platform = plugin_event.platform['platform']
)
Expand All @@ -219,7 +227,7 @@ def unity_reply(plugin_event, Proc):
tmp_reply_str = dictStrCustom['strLoggerLogAlreadyOff'].format(**dictTValue)
OlivaDiceCore.userConfig.writeUserConfigByUserHash(
userHash = OlivaDiceCore.userConfig.getUserHash(
userId = plugin_event.data.group_id,
userId = tmp_hagID,
userType = 'group',
platform = plugin_event.platform['platform']
)
Expand All @@ -233,12 +241,12 @@ def unity_reply(plugin_event, Proc):
userConfigKey = 'logEnable',
userConfigValue = False,
botHash = plugin_event.bot_info.hash,
userId = plugin_event.data.group_id,
userId = tmp_hagID,
userType = 'group',
platform = plugin_event.platform['platform']
)
tmp_logName = OlivaDiceCore.userConfig.getUserConfigByKey(
userId = plugin_event.data.group_id,
userId = tmp_hagID,
userType = 'group',
platform = plugin_event.platform['platform'],
userConfigKey = 'logNowName',
Expand All @@ -249,7 +257,7 @@ def unity_reply(plugin_event, Proc):
userConfigKey = 'logNowName',
userConfigValue = None,
botHash = plugin_event.bot_info.hash,
userId = plugin_event.data.group_id,
userId = tmp_hagID,
userType = 'group',
platform = plugin_event.platform['platform']
)
Expand All @@ -271,7 +279,7 @@ def unity_reply(plugin_event, Proc):
replyMsg(plugin_event, tmp_reply_str)
OlivaDiceCore.userConfig.writeUserConfigByUserHash(
userHash = OlivaDiceCore.userConfig.getUserHash(
userId = plugin_event.data.group_id,
userId = tmp_hagID,
userType = 'group',
platform = plugin_event.platform['platform']
)
Expand Down

0 comments on commit fb8917a

Please sign in to comment.