Skip to content

Commit

Permalink
Update command (#14)
Browse files Browse the repository at this point in the history
* Update command
* Support more string type in rand
* Add tutorial for roll plugin
  • Loading branch information
he0119 authored Apr 14, 2019
1 parent 9230182 commit 3dcd626
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 54 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@

## [Unreleased]

## [0.6.2] - 2019-04-14

### Changed

- 移除了检测状态并重启 `酷Q` 的功能
- 升级 `CoolQBot-env``v0.2.1`
- 改进了 `rank` 插件的正则表达式,现在可以使用 `/rank n100`
- 改进了所有差价的正则表达式,现在命令与参数之间必须要有空格
- `ban` 插件的参数调整为禁言分钟数

## [0.6.1] - 2019-03-28

Expand Down Expand Up @@ -153,7 +158,8 @@

- 正常工作的版本。

[Unreleased]: https://github.com/he0119/CoolQBot/compare/v0.6.1...HEAD
[Unreleased]: https://github.com/he0119/CoolQBot/compare/v0.6.2...HEAD
[0.6.2]: https://github.com/he0119/CoolQBot/compare/v0.6.1...v0.6.2
[0.6.1]: https://github.com/he0119/CoolQBot/compare/v0.6.0...v0.6.1
[0.6.0]: https://github.com/he0119/CoolQBot/compare/v0.5.2...v0.6.0
[0.5.2]: https://github.com/he0119/CoolQBot/compare/v0.5.1...v0.5.2
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/ban.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

@bot.on_message('group', 'private')
async def ban(context):
match = re.match(r'^\/ban ?(\w*)?', context['message'])
match = re.match(r'^\/ban(?: (\d*))?$', context['message'])
if match:
args = match.group(1)

# 默认10分钟
duration = 10 * 60

if args:
duration = int(args)
duration = int(args) * 60
else:
# 默认10分钟
duration = 10 * 60

await bot.set_group_ban(group_id=GROUP_ID, user_id=context['user_id'], duration=duration)
2 changes: 1 addition & 1 deletion src/plugins/bilibili.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@bot.on_message('group', 'private')
async def bilibili_today(context):
match = re.match(r'^\/bilibili', context['message'])
match = re.match(r'^\/bilibili$', context['message'])
if match:
try:
output = ''
Expand Down
24 changes: 13 additions & 11 deletions src/plugins/gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,30 @@

from coolqbot.bot import bot

TEXTS = ['掐指一算,你应该走[direction]!',
'夜观天象,你应该走[direction]!',
'冷静分析,你应该走[direction]!',
'一拍大腿,你应该走[direction]!',
'我寻思,走[direction]一定可以到7层',
'想了想,走[direction]应该是最好的选择!',
'走[direction],准没错!难道你不相信可爱的小誓约吗!',
'投了个硬币,仔细一看,走[direction]。不信我,难道你还不信硬币么!',
'直觉告诉我,你走[direction]就会马上出去......']
TEXTS = [
'掐指一算,你应该走[direction]!',
'夜观天象,你应该走[direction]!',
'冷静分析,你应该走[direction]!',
'一拍大腿,你应该走[direction]!',
'我寻思,走[direction]一定可以到7层',
'想了想,走[direction]应该是最好的选择!',
'走[direction],准没错!难道你不相信可爱的小誓约吗!',
'投了个硬币,仔细一看,走[direction]。不信我,难道你还不信硬币么!',
'直觉告诉我,你走[direction]就会马上出去......'
]


@bot.on_message('group', 'private')
async def gate(context):
match = re.match(r'^\/gate ?(\w*)?', context['message'])
match = re.match(r'^\/gate(?: (\d*))?$', context['message'])
if match:
args = match.group(1)

door_number = 2
if args == '3':
door_number = 3

text_index = randint(0, len(TEXTS)-1)
text_index = randint(0, len(TEXTS) - 1)

direction = get_direction(door_number)

Expand Down
37 changes: 25 additions & 12 deletions src/plugins/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
DATA = PluginData('history')


@scheduler.scheduled_job('cron', day=1, hour=0, minute=0, second=0, id='clear_data')
@scheduler.scheduled_job('cron',
day=1,
hour=0,
minute=0,
second=0,
id='clear_data')
async def clear_data():
""" 每个月最后24点(下月0点)保存记录于历史记录文件夹,并重置记录
"""
Expand All @@ -28,8 +33,7 @@ async def clear_data():

@bot.on_message('group', 'private')
async def history(context):
match = re.match(r'^\/history ?(\d+)\-?(\d+)?|^\/history',
context['message'])
match = re.match(r'^\/history(?: (\d+)(?:\-(\d+))?)?$', context['message'])
if match:
str_data = ''

Expand All @@ -40,20 +44,25 @@ async def history(context):
if month:
month = int(month)

if not year:
str_data = '欢迎查询历史记录\n如需查询上月数据请输入/history 1\n如需查询指定月份请输入/history year-month(如2018-01)'
if not year and year != 0:
str_data = '欢迎查询历史记录\n如需查询上月数据请输入/history 0\n如需查询指定月份请输入/history year-month(如2018-01)'
return {'reply': str_data, 'at_sender': False}

if year and month:
if not month:
if year == 0:
date = datetime.now() - relativedelta(months=1)
else:
str_data = '请输入月份,只有年份我也不知道查什么呀!'
return {'reply': str_data, 'at_sender': False}

if month and year:
if year < 1 or year > 9999:
str_data = '请输入1到9999的年份,超过了我就不能查惹'
str_data = '请输入1到9999的年份,超过了我就不能查惹'
return {'reply': str_data, 'at_sender': False}
if month > 12:
str_data = '请输入正确的月份,众所周知,一年只有12个月'
str_data = '请输入正确的月份,众所周知,一年只有12个月'
return {'reply': str_data, 'at_sender': False}
date = datetime(year=year, month=month, day=1)
else:
date = datetime.now() - relativedelta(months=1)

# 尝试读取历史数据
history_filename = get_history_pkl_name(date)
Expand All @@ -70,8 +79,12 @@ async def history(context):
repeat_list = history_data['repeat_list']
msg_number_list = history_data['msg_number_list']

repeat_rate_ranking = await get_repeat_rate_ranking(repeat_list, msg_number_list, display_number, minimal_msg_number, display_total_number)
repeat_number_ranking = await get_repeat_number_ranking(repeat_list, msg_number_list, display_number, minimal_msg_number, display_total_number)
repeat_rate_ranking = await get_repeat_rate_ranking(
repeat_list, msg_number_list, display_number, minimal_msg_number,
display_total_number)
repeat_number_ranking = await get_repeat_number_ranking(
repeat_list, msg_number_list, display_number, minimal_msg_number,
display_total_number)

if repeat_rate_ranking and repeat_rate_ranking:
str_data = f'{date.year}{date.month}月数据\n'
Expand Down
17 changes: 10 additions & 7 deletions src/plugins/morning.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@
SECOND = int(DATA.config_get('morning', 'second', fallback='0'))


@scheduler.scheduled_job('cron', hour=HOUR, minute=MINUTE, second=SECOND, id='morning')
@scheduler.scheduled_job('cron',
hour=HOUR,
minute=MINUTE,
second=SECOND,
id='morning')
async def morning():
""" 早安
"""
hello_str = get_message()
await bot.send_msg(message_type='group', group_id=GROUP_ID, message=hello_str)
await bot.send_msg(message_type='group',
group_id=GROUP_ID,
message=hello_str)
bot.logger.info('发送问好信息')


TEXTS = ['早上好呀~>_<~',
'大家早上好呀!',
'朋友们早上好!',
'圆神的信徒们早上好~']
TEXTS = ['早上好呀~>_<~', '大家早上好呀!', '朋友们早上好!', '圆神的信徒们早上好~']


def get_message():
Expand All @@ -43,7 +46,7 @@ def get_message():
except:
res = {'code': -1}

text_index = randint(0, len(TEXTS)-1)
text_index = randint(0, len(TEXTS) - 1)
str_data = f'{TEXTS[text_index]}\n'

if res['code'] == 0:
Expand Down
11 changes: 7 additions & 4 deletions src/plugins/rand.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@

@bot.on_message('group', 'private')
async def rand(context):
match = re.match(r'^\/rand ?(\w*)?', context['message'])
match = re.match(r'^\/rand(?: (.*)?)?$', context['message'])
if match:
args = match.group(1)
text = match.group(1)
str_data = ''

probability = re.match(r'\w+(可能性|几率|概率)$', args)
if not text:
text = ''

probability = re.match(r'^.+(可能性|几率|概率)$', text)
if probability:
str_data += args
str_data += text
str_data += '是 '
str_data += str(randint(0, 100))
str_data += '%'
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@bot.on_message('group', 'private')
async def rank(context):
match = re.match(r'^\/rank(?: (?:(\d+))?(?:n(\d+))?)?', context['message'])
match = re.match(r'^\/rank(?: (?:(\d+))?(?:n(\d+))?)?$', context['message'])
if match:
display_number = match.group(1)
minimal_msg_number = match.group(2)
Expand Down
10 changes: 6 additions & 4 deletions src/plugins/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ def save_data(self):
self._data.save_pkl(self.get_data(), self._name)

def get_data(self):
return {'last_message_on': self.last_message_on,
'msg_send_time': self.msg_send_time,
'repeat_list': self.repeat_list,
'msg_number_list': self.msg_number_list}
return {
'last_message_on': self.last_message_on,
'msg_send_time': self.msg_send_time,
'repeat_list': self.repeat_list,
'msg_number_list': self.msg_number_list
}

def clear_data(self):
self.msg_send_time = []
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/repeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def is_repeat(msg):
return False

# 不要复读指令
match = re.match(r'\/', msg['message'])
match = re.match(r'^\/', msg['message'])
if match:
return False

Expand All @@ -36,7 +36,7 @@ def is_repeat(msg):
recorder.msg_send_time.append(now)

# 如果不是PRO版本则不复读纯图片
match = re.search(r'^\[CQ:image[^\]]+\]$', msg['message'])
match = re.search(r'\[CQ:image[^\]]+\]$', msg['message'])
if match and not IS_COOLQ_PRO:
return False

Expand All @@ -45,7 +45,7 @@ def is_repeat(msg):
return False

# 不要复读签到,分享
match = re.match(r'\[CQ:(sign|share).+\]', msg['message'])
match = re.match(r'^\[CQ:(sign|share).+\]', msg['message'])
if match:
return False

Expand Down
12 changes: 9 additions & 3 deletions src/plugins/roll.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@

@bot.on_message('group', 'private')
async def roll(context):
match = re.match(r'^\/roll ?(.*)?$', context['message'])
match = re.match(r'^\/roll(?: (.*))?$', context['message'])
if match:
str_data = roll_dices(match.group(1))
args = match.group(1)

if args:
str_data = roll_dices(args)
else:
str_data = '欢迎使用 NGA 风格 ROLL 点插件\n你可以 /roll d100\n也可以 /roll 2d100+2d50'

return {'reply': str_data, 'at_sender': False}


Expand All @@ -29,7 +35,7 @@ def roll_dices(input_str):
dice_str, add = roll_single(dice, add)
r += dice_str
raw_str += f'{dice[0]}{dice[1]}{dice[2]}{dice[3]}'
return f'{raw_str}={r}={add}'[1:].replace('=+', '=')
return f'{raw_str}={r}={add}' [1:].replace('=+', '=')


def roll_single(args, add):
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@bot.on_message('group', 'private')
async def status(context):
match = re.match(r'^\/(status|状态)', context['message'])
match = re.match(r'^\/(status|状态)$', context['message'])
if match:
str_data = f'近十分钟群内聊天数量是{recorder.message_number(10)}条'
repeat_num = get_total_number(recorder.repeat_list)
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@bot.on_message('group', 'private')
async def weather(context):
match = re.match(r'^\/天气 ?(\w*)?', context['message'])
match = re.match(r'^\/(?:天气|weather)(?: (\w*))?$', context['message'])
if match:
city = match.group(1)
str_data = weather_old(city)
Expand Down

0 comments on commit 3dcd626

Please sign in to comment.