Skip to content

Commit

Permalink
Merge branch 'Teahouse-Studios:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
DoroWolf authored Jul 31, 2024
2 parents c3e9127 + e5f65ed commit cb46a38
Show file tree
Hide file tree
Showing 19 changed files with 59 additions and 79 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@

# 小可 · AkariBot v4

_基于 OneBot 11 开发的可扩展、多平台机器人_

[![GitHub issues](https://img.shields.io/github/issues/Teahouse-Studios/akari-bot)](https://github.com/Teahouse-Studios/akari-bot/issues)
[![GitHub pull requests](https://img.shields.io/github/issues-pr/Teahouse-Studios/akari-bot)](https://github.com/Teahouse-Studios/akari-bot/pulls)<!--![GitHub tag](https://img.shields.io/github/v/tag/Teahouse-Studios/akari-bot?include_prereleases)-->
[![Crowdin](https://badges.crowdin.net/akari-bot/localized.svg)](https://crowdin.com/project/akari-bot)
![GitHub Repo stars](https://img.shields.io/github/stars/Teahouse-Studios/akari-bot?style=social)
<br>
![Python](https://img.shields.io/badge/Python-3.12+-blue)
![OneBot v11](https://img.shields.io/badge/OneBot-v11-black?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAAAIVBMVEUAAAAAAAADAwMHBwceHh4UFBQNDQ0ZGRkoKCgvLy8iIiLWSdWYAAAAAXRSTlMAQObYZgAAAQVJREFUSMftlM0RgjAQhV+0ATYK6i1Xb+iMd0qgBEqgBEuwBOxU2QDKsjvojQPvkJ/ZL5sXkgWrFirK4MibYUdE3OR2nEpuKz1/q8CdNxNQgthZCXYVLjyoDQftaKuniHHWRnPh2GCUetR2/9HsMAXyUT4/3UHwtQT2AggSCGKeSAsFnxBIOuAggdh3AKTL7pDuCyABcMb0aQP7aM4AnAbc/wHwA5D2wDHTTe56gIIOUA/4YYV2e1sg713PXdZJAuncdZMAGkAukU9OAn40O849+0ornPwT93rphWF0mgAbauUrEOthlX8Zu7P5A6kZyKCJy75hhw1Mgr9RAUvX7A3csGqZegEdniCx30c3agAAAABJRU5ErkJggg==)
[![License](https://img.shields.io/github/license/Teahouse-Studios/akari-bot)](https://github.com/Teahouse-Studios/akari-bot/blob/master/LICENSE)
</div>

![GitHub issues](https://img.shields.io/github/issues/Teahouse-Studios/akari-bot) ![GitHub pull requests](https://img.shields.io/github/issues-pr/Teahouse-Studios/akari-bot) ![License](https://img.shields.io/github/license/Teahouse-Studios/akari-bot) ![GitHub tag](https://img.shields.io/github/v/tag/Teahouse-Studios/akari-bot?include_prereleases) [![Crowdin](https://badges.crowdin.net/akari-bot/localized.svg)](https://crowdin.com/project/akari-bot) ![GitHub Repo stars](https://img.shields.io/github/stars/Teahouse-Studios/akari-bot?style=social)

## 介绍

**小可**是基于多个框架开发的可扩展、多平台机器人。当前形象由 [OasisAkari](https://github.com/OasisAkari) 绘制。
**小可**是基于 OneBot 11 开发的可扩展、多平台机器人。当前形象由 [OasisAkari](https://github.com/OasisAkari) 绘制。

目前小可还正在持续开发中。

Expand Down
1 change: 0 additions & 1 deletion core/utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ async def download_(filename=filename, path=path):
private_ip_check(url)

data = None

if method.upper() == 'GET':
data = await get_url(url, status_code=status_code, headers=headers, fmt='read', timeout=timeout, attempt=1,
request_private_ip=request_private_ip, logging_err_resp=logging_err_resp)
Expand Down
5 changes: 1 addition & 4 deletions modules/bilibili/bili_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import traceback

from core.builtins import Bot, Embed, EmbedField, ErrorMessage, Image, Plain, Url
from core.logger import Logger
from core.utils.http import get_url
from core.utils.web_render import webrender

Expand All @@ -23,7 +20,7 @@ async def get_video_info(msg: Bot.MessageSession, query, get_detail=False, use_e
if str(e).startswith('412'):
await msg.finish(ErrorMessage('{bilibili.message.error.rejected}', locale=msg.locale.locale))
else:
Logger.error(traceback.format_exc())
raise e

view = res['data']['View']
stat = view['stat']
Expand Down
3 changes: 1 addition & 2 deletions modules/bugtracker/bugtracker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import traceback

import aiohttp
import ujson as json
Expand Down Expand Up @@ -59,7 +58,7 @@ async def bugtracker_get(msg, mojira_id: str):
if str(e).startswith('401'):
return msg.locale.t("bugtracker.message.get_failed"), None
else:
Logger.error(traceback.format_exc())
raise e
if mojira_id not in spx_cache:
get_spx = await get_url('https://spxx-db.teahouse.team/crowdin/zh-CN/zh_CN.json', 200)
if get_spx:
Expand Down
5 changes: 1 addition & 4 deletions modules/cytoid/profile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import traceback

import ujson as json

from core.builtins import Bot, Image, Plain
from core.logger import Logger
from core.utils.http import get_url


Expand All @@ -15,7 +12,7 @@ async def cytoid_profile(msg: Bot.MessageSession, uid):
if str(e).startswith('404'):
await msg.finish(msg.locale.t('cytoid.message.user_not_found'))
else:
Logger.error(traceback.format_exc())
raise e
uid = profile['user']['uid']
nick = profile['user']['name']
avatar = profile['user']['avatar']['large']
Expand Down
7 changes: 6 additions & 1 deletion modules/dice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
dice = module('dice', alias=['rd', 'roll'], developers=['Light-Beacon', 'DoroWolf'], desc='{dice.help.desc}')


@dice.command()
async def _(msg: Bot.MessageSession):
await msg.finish(await process_expression(msg, 'D', None))


@dice.command('<dices> [<dc>] {{dice.help}}')
async def _(msg: Bot.MessageSession, dices: str, dc=None):
async def _(msg: Bot.MessageSession, dices: str, dc: int = None):
await msg.finish(await process_expression(msg, dices, dc))


Expand Down
5 changes: 0 additions & 5 deletions modules/dice/dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class Dice(DiceItemBase):

def __init__(self, msg: Bot.MessageSession, dice_code: str):

dice_code = dice_code.replace(' ', '')
super().__init__(dice_code)
args = self.GetArgs(msg)
self.count = args[0]
Expand Down Expand Up @@ -168,7 +167,6 @@ class FudgeDice(DiceItemBase):

def __init__(self, msg: Bot.MessageSession, dice_code: str):

dice_code = dice_code.replace(' ', '')
super().__init__(dice_code)
args = self.GetArgs(msg)
self.count = args[0]
Expand Down Expand Up @@ -224,7 +222,6 @@ class BonusPunishDice(DiceItemBase):

def __init__(self, msg: Bot.MessageSession, dice_code: str):

dice_code = dice_code.replace(' ', '')
super().__init__(dice_code)
args = self.GetArgs(msg)
self.count = args[0]
Expand Down Expand Up @@ -306,7 +303,6 @@ class WODDice(DiceItemBase):

def __init__(self, msg: Bot.MessageSession, dice_code: str):

dice_code = dice_code.replace(' ', '')
super().__init__(dice_code)
args = self.GetArgs(msg)
self.count = args[0]
Expand Down Expand Up @@ -568,7 +564,6 @@ class DXDice(DiceItemBase):

def __init__(self, msg: Bot.MessageSession, dice_code: str):

dice_code = dice_code.replace(' ', '')
super().__init__(dice_code)
args = self.GetArgs(msg)
self.count = args[0]
Expand Down
1 change: 0 additions & 1 deletion modules/dice/locales/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"dice.help.set": "Set the default sides number of dice.",
"dice.message.dc.check": "▷ Success: ${success} Failure: ${failed}",
"dice.message.dc.failed": "Failed!",
"dice.message.dc.invalid": "Invalid DC: ",
"dice.message.dc.success": "Success!",
"dice.message.error": "Unable to parse the dice expression: ",
"dice.message.error.invalid": "Unrecognized characters in dice expression.",
Expand Down
1 change: 0 additions & 1 deletion modules/dice/locales/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"dice.help.set": "设置默认骰子面数。",
"dice.message.dc.check": "▷ 判定成功数量:${success} 判定失败数量:${failed}",
"dice.message.dc.failed": "失败!",
"dice.message.dc.invalid": "无效的 DC:",
"dice.message.dc.success": "成功!",
"dice.message.error": "无法解析骰子表达式:",
"dice.message.error.invalid": "骰子表达式中存在无法识别的字符。",
Expand Down
1 change: 0 additions & 1 deletion modules/dice/locales/zh_tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"dice.help.set": "設定預設骰子面數。",
"dice.message.dc.check": "▷ 判定成功數量:${success} 判定失敗數量:${failed}",
"dice.message.dc.failed": "失敗!",
"dice.message.dc.invalid": "無效的 DC:",
"dice.message.dc.success": "成功!",
"dice.message.error": "無法解析骰子運算式:",
"dice.message.error.invalid": "骰子運算式中存在無法辨識的字元。",
Expand Down
22 changes: 10 additions & 12 deletions modules/github/repo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import asyncio
import traceback
import uuid

from core.builtins import Bot, Image, Plain, Url
from core.dirty_check import rickroll
from core.logger import Logger
from core.utils.http import get_url
from core.utils.http import download, get_url
from modules.github.utils import time_diff, dirty_check, darkCheck


Expand Down Expand Up @@ -59,16 +57,16 @@ async def repo(msg: Bot.MessageSession, name: str):
else:
await msg.send_message([Plain(message)])

async def download():
download_pic = await download(
f'https://opengraph.githubassets.com/c9f4179f4d560950b2355c82aa2b7750bffd945744f9b8ea3f93cc24779745a0/{result["full_name"]}')
if download_pic:
await msg.finish([Image(download_pic)], quote=False)

asyncio.create_task(download())
hash = str(uuid.uuid4())
download_pic = await download(
url=f'https://opengraph.githubassets.com/{hash}/{result["full_name"]}',
filename=f'{hash}.png'
)
if download_pic:
await msg.finish([Image(download_pic)], quote=False)

except ValueError as e:
if str(e).startswith('404'):
await msg.finish(msg.locale.t("github.message.repo.not_found"))
else:
Logger.error(traceback.format_exc())
raise e
44 changes: 19 additions & 25 deletions modules/github/search.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
import traceback

from core.builtins import Bot, Url
from core.dirty_check import rickroll
from core.logger import Logger
from core.utils.http import get_url
from modules.github.utils import dirty_check, darkCheck


async def search(msg: Bot.MessageSession, keyword: str):
try:
result = await get_url('https://api.github.com/search/repositories?q=' + keyword, 200,
fmt='json')
if result['total_count'] == 0:
message = msg.locale.t("github.message.search.not_found")
else:
items = result['items']
items_out = []
for item in items:
try:
items_out.append(str(item['full_name'] + ': ' + str(Url(item['html_url']))))
except TypeError:
continue
message = msg.locale.t("github.message.search") + '\n' + '\n'.join(items_out[0:5])
if result['total_count'] > 5:
message += '\n' + msg.locale.t("message.collapse", amount="5")
result = await get_url('https://api.github.com/search/repositories?q=' + keyword, 200,
fmt='json')
if result['total_count'] == 0:
message = msg.locale.t("github.message.search.not_found")
else:
items = result['items']
items_out = []
for item in items:
try:
items_out.append(str(item['full_name'] + ': ' + str(Url(item['html_url']))))
except TypeError:
continue
message = msg.locale.t("github.message.search") + '\n' + '\n'.join(items_out[0:5])
if result['total_count'] > 5:
message += '\n' + msg.locale.t("message.collapse", amount="5")

is_dirty = await dirty_check(message) or darkCheck(message)
if is_dirty:
await msg.finish(rickroll(msg))
is_dirty = await dirty_check(message) or darkCheck(message)
if is_dirty:
await msg.finish(rickroll(msg))

await msg.finish(message)
except BaseException:
Logger.error(traceback.format_exc())
await msg.finish(message)
5 changes: 1 addition & 4 deletions modules/github/user.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import traceback

from core.builtins import Url, Bot
from core.dirty_check import rickroll
from core.logger import Logger
from core.utils.http import get_url
from modules.github.utils import time_diff, dirty_check, darkCheck

Expand Down Expand Up @@ -48,4 +45,4 @@ async def user(msg: Bot.MessageSession, name: str):
if str(e).startswith('404'):
await msg.finish(msg.locale.t("github.message.repo.not_found"))
else:
Logger.error(traceback.format_exc())
raise e
4 changes: 2 additions & 2 deletions modules/github/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def darkCheck(message: str):
]
if Config('enable_dirty_check', False):
for i in blacklist:
if message.find(i) > -1:
if message.find(i) != -1:
return True
return False
else:
Expand Down Expand Up @@ -62,6 +62,6 @@ async def dirty_check(text: str, *allowlist_check):
if allowlist_check in allowlist:
return False
check = await dirty.check_bool(text)
if not check:
if check:
return True
return False
3 changes: 1 addition & 2 deletions modules/osu/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from config import Config
from core.builtins import Bot
from core.exceptions import ConfigValueError
from core.logger import Logger
from core.utils.http import get_url


Expand Down Expand Up @@ -65,7 +64,7 @@ async def osu_profile(msg: Bot.MessageSession, uid, mode):
if str(e).startswith('401'):
raise ConfigValueError(msg.locale.t("error.config.invalid"))
else:
Logger.error(traceback.format_exc())
raise e
except Exception:
Logger.error(traceback.format_exc())
await msg.finish(msg.locale.t('osu.message.not_found'))
Expand Down
4 changes: 1 addition & 3 deletions modules/tweet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import re
import traceback

import ujson as json

from core.builtins import Bot
from core.builtins.message import Image, Url
from core.component import module
from core.dirty_check import check_bool, rickroll
from core.logger import Logger
from core.utils.http import download, get_url
from core.utils.text import isint
from core.utils.web_render import webrender
Expand Down Expand Up @@ -41,7 +39,7 @@ async def _(msg: Bot.MessageSession, tweet: str):
if str(e).startswith('404'):
await msg.finish(msg.locale.t('tweet.message.invalid'))
else:
Logger.error(traceback.format_exc())
raise e

res_json = json.loads(res)
if not res_json['data']:
Expand Down
3 changes: 1 addition & 2 deletions modules/wiki/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from core.builtins import Bot
from core.component import module
from core.logger import Logger
from modules.wiki.utils.dbutils import WikiTargetInfo, Audit
from modules.wiki.utils.wikilib import WikiLib, WhatAreUDoingError, PageInfo, InvalidWikiError, QueryInfo
from modules.wiki.utils.dbutils import WikiTargetInfo
from .ab import ab
from .ab_qq import ab_qq
from .newbie import newbie
Expand Down
4 changes: 2 additions & 2 deletions modules/wiki/utils/wikilib.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ async def search_something(srwhat):
page_info.link = full_url
page_info.file = file
page_info.desc = page_desc
if not _iw and not page_info.args:
if not _iw and not page_info.args and page_info.id != -1:
page_info.link = self.wiki_info.script + f'?curid={page_info.id}'
else:
page_info.title = query_langlinks.title
Expand Down Expand Up @@ -758,7 +758,7 @@ async def search_something(srwhat):
page_info.before_title = before_page_info.title
t = page_info.title
if t:
if before_page_info.args:
if before_page_info.args or page_info.id == -1:
page_info.before_title += urllib.parse.unquote(before_page_info.args)
t += urllib.parse.unquote(before_page_info.args)
if page_info.link:
Expand Down
6 changes: 2 additions & 4 deletions modules/wolframalpha/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import traceback
import urllib.parse
from PIL import Image

Expand All @@ -8,7 +7,6 @@
from core.component import module
from core.dirty_check import rickroll
from core.exceptions import ConfigValueError
from core .logger import Logger
from core.utils.http import download, get_url
from .check import secret_check

Expand Down Expand Up @@ -44,7 +42,7 @@ async def _(msg: Bot.MessageSession, query: str):
if str(e).startswith('501'):
await msg.finish(msg.locale.t('wolframalpha.message.incomprehensible'))
else:
Logger.error(traceback.format_exc())
raise e


@w.handle('ask <question> {{wolframalpha.help.ask}}')
Expand All @@ -62,4 +60,4 @@ async def _(msg: Bot.MessageSession, question: str):
if str(e).startswith('501'):
await msg.finish(msg.locale.t('wolframalpha.message.incomprehensible'))
else:
Logger.error(traceback.format_exc())
raise e

0 comments on commit cb46a38

Please sign in to comment.