Skip to content

Commit

Permalink
Update homepage & Clean debug code
Browse files Browse the repository at this point in the history
  • Loading branch information
Hentioe_Cl committed Jun 30, 2019
1 parent 60ef31a commit 3dc15e8
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 66 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PolicrBot 的主要作用和目的是排除潜在的加群机器人,它通过

由于高度抽象的设计,支持新的验证方式变得非常容易。本项目会考虑一切值得推荐的验证机制,但不会支持验证码([原因请看这里](https://policr.bluerain.io#verification_code))。

我们不会提供类似 `CNBlacklistR` 这种简单又不透明的黑名单功能。但好消息是初版黑名单系统已经构思完成并在实现中,详情[看这里](https://github.com/Hentioe/policr/issues/20)
我们不会提供类似 `CNBlacklistR` 这种简单又不透明的黑名单功能。好消息是初版黑名单系统已经构思完成并在实现中,详情[看这里](https://github.com/Hentioe/policr/issues/20)

### 开发技术

Expand All @@ -43,6 +43,9 @@ PolicrBot 的主要作用和目的是排除潜在的加群机器人,它通过
- [x] 申请令牌
- [ ] 高级设置
- [ ] 管理多套自定义验证
- [ ] 封禁记录
- [ ] 查看封禁列表
- [ ] 解除封禁
- [x] 全网黑名单
- [x] 举报功能
- [ ] 投票功能
Expand Down
1 change: 0 additions & 1 deletion config/initializers/database.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Jennifer::Config.configure do |conf|

env = ENV["POLICR_ENV"]? || "dev"
db_path = "#{Policr::CLI::Config.instance.dpath}/#{env}.db"
puts db_path
conf.db = db_path

conf.logger.level = Logger::DEBUG
Expand Down
29 changes: 28 additions & 1 deletion locales/zh_hans.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_to_group:
from_user: "噔噔噔噔!史上最强大的群审核机器人入场了!诶?你都没权限瞎邀啥啊!不管了,既然如此那就请把我弄过来的变态([%{name}](tg://user?id=%{user_id}))负起责任,尽快联系群主进行设置以让我工作起来,不然我过 30分钟 就会自己溜掉哦!\n\n附加阅读:[如何使用我?](https://policr.bluerain.io)"
from_admin: "请把我弄过来的变态([%{name}](tg://user?id=%{user_id}))负起责任,进行基本设置以让我工作起来。注意了,如果你不是群主,你需要先通过群主启用信任管理员,不然你也是无法控制我的哟~\n如果你们决定不使用我,请点击下方的按钮让我自己离开,做机器人呐也得有尊严!\n\n附加阅读:[如何使用我?](https://policr.bluerain.io)"
no_permission: "请联系管理员使用此按钮!"
subscription_update: "订阅更新"
captcha:
desc: "你知道吗?本机器人同时支持多种验证方式。下面分别为您简短介绍:\n\n1. 默认验证,傻瓜式的存在一个正确和一个错误答案\n2. 定制验证,通过此方式可以定制属于群组自己的验证问题,您需要点击下方的按钮,再按照变化后的说明文本进行回复\n3. 动态验证,会随机生成例如简单计算公式一类的纯动态问题,目前处于测试阶段\n4. 图片验证,让入群用户识别图片内容。与 Google 图片验证类似,但与之相反。它提供一张图片而附带多个候选词汇\n\n注意:以上四种只可选其一,定制验证需要得到回复以后才会刷新下方单选状态。"
default: "已恢复默认验证。注意,默认验证并不是永久固定的,它会随着机器人的不断更新而改进。"
Expand Down Expand Up @@ -84,9 +85,35 @@ pass_by_admin: "Σ(\\*゚д゚ノ)ノ [这家伙](tg://user?id=%{user_id})走后
pass_slow_alert: "验证通过,但是晚了一点点,再去试试?"
pass_slow_receipt: "(´゚д゚`) TA通过了验证,但是手慢了那么一点点,再给TA一次机会……"
report:
admin_reply: "举报开始,请选择具体原因。举报将在完成选择以后被创建,并进入[黑名单公投频道](https://t.me/policr_blacklist_voting)进行投票。如果您决定放弃举报,则不需要做任何选择。\n\n注意:在完成举报前请不要删除被举报消息。"
admin_reply: "举报开始,请选择具体原因。举报将在完成选择以后被创建,并进入[黑名单公投频道](https://t.me/%{voting_channel})进行投票。如果您决定放弃举报,则不需要做任何选择。\n\n注意:在完成举报前请不要删除被举报消息。"
mass_ad: "恶意散播广告"
unident_halal: "未识别的清真"
forward_error: "举报发起失败,原因:%{reason}"
storage_error: "举报生成失败,原因:%{reason}"
voting_message: |
举报发起人:[%{author_id}](tg://user?id=%{author_id})
举报人身份:%{role}
举报目标快照:[%{post_id}](https://t.me/%{snapshot_channel}/%{post_id})
被执行用户:[%{target_id}](tg://user?id=%{target_id})
举报原因:%{reason}
当前状态:%{status}
generated: "举报已经生成([在这里](https://t.me/%{voting_channel}/%{voting_message_id})),具有投票权的用户会对举报内容进行表决。注意了,[您](tg://user?id=%{user_id})作为发起人不能进行投票。如果举报受理成功将会在本群通知。"
role:
unknown: "未知"
creator: "群主"
trusted_admin: "受信管理员"
admin: "管理员"
member: "群成员"
reason:
unknown: "未记录"
spam: "恶意散播广告"
halal: "未识别的清真"
status:
unknown: "不明"
begin: "#表决中"
reject: "不受理"
accept: "被处理"
unban: "通过申诉"
after_event:
tip: "[事后审核](https://policr.bluerain.io#afterwards),请主动完成验证以解除限制。"
torture: "开始验证"
Expand Down
24 changes: 0 additions & 24 deletions src/policr.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ module Policr
snapshot_channel = ENV["#{ENV_PREFIX}_SNAPSHOT_CHANNEL"]
voting_channel = ENV["#{ENV_PREFIX}_VOTING_CHANNEL"]

# test_db

bot = Bot.new(
username,
token,
Expand All @@ -50,28 +48,6 @@ module Policr

bot.polling
end

def self.test_db

author_id = 340396281.to_i64
post_id = 29
target_id = 871769395.to_i64
reason = 1
status = 1
role = 1
from_chat = -1001301664514.to_i64

r1 = Model::Report.create({
author_id: author_id,
post_id: post_id,
target_id: target_id,
reason: reason,
status: status,
role: role,
from_chat: from_chat,
})
puts "Created result: #{r1.inspect}"
end
end

Policr.start unless ENV["POLICR_ENV"]? == "test"
2 changes: 2 additions & 0 deletions src/policr/bot.cr
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ module Policr

getter snapshot_channel : String
getter voting_channel : String
getter username : String

def initialize(username, token, logger, snapshot_channel, voting_channel)
super(username, token, logger: logger)
@snapshot_channel = snapshot_channel
@voting_channel = voting_channel
@username = username

me = get_me || raise Exception.new("Failed to get bot data")
@self_id = me["id"].as_i64
Expand Down
49 changes: 30 additions & 19 deletions src/policr/callbacks/report.cr
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Policr
)
rescue e : TelegramBot::APIException
_, reason = bot.parse_error(e)
bot.answer_callback_query(query.id, text: "举报发起失败,原因:#{reason}")
bot.answer_callback_query(query.id, text: t("report.forward_error", {reason: reason}))
return
end

Expand Down Expand Up @@ -67,16 +67,23 @@ module Policr
role: role.value,
from_chat: chat_id.to_i64,
}
puts data.inspect
r = Model::Report.create!(data)
rescue e : Exception
puts e.inspect
bot.answer_callback_query(query.id, text: "举报入库失败,原因:#{e.message}")
bot.answer_callback_query(query.id, text: t("report.storage_error", {reason: e.message}))
end
end
# 生成投票
if r
text = "举报发起人:[#{r.author_id}](tg://user?id=#{r.author_id})\n举报人身份:#{make_role(r.role)}\n举报目标快照:[#{r.post_id}](https://t.me/#{bot.snapshot_channel}/#{r.post_id})\n被执行用户:[#{r.target_id}](tg://user?id=#{r.target_id})\n举报原因:#{make_reason(r.reason)}\n当前状态:#{make_status(r.status)}"
inject_data = {
author_id: r.author_id,
role: make_role(r.role),
post_id: r.post_id,
snapshot_channel: bot.snapshot_channel,
target_id: target_user_id,
reason: make_reason(r.reason),
status: make_status(r.status),
}
text = t "report.voting_message", inject_data

report_id = r.id
markup = Markup.new
Expand All @@ -99,7 +106,11 @@ module Policr

# 响应举报生成结果
if voting_msg
text = "举报已经生成([在这里](https://t.me/#{bot.voting_channel}/#{voting_msg.message_id})),具有投票权的用户会对举报内容进行表决。注意了,[您](tg://user?id=#{from_user_id})作为发起人不能进行投票。举报受理成功将会在本群通知。"
text = t "report.generated", {
voting_channel: bot.voting_channel,
voting_message_id: voting_msg.message_id,
user_id: from_user_id,
}
bot.edit_message_text(
chat_id: chat_id,
message_id: msg.message_id,
Expand All @@ -113,41 +124,41 @@ module Policr
def make_role(role_value)
case UserRole.new(role_value)
when UserRole::Unknown
"未知"
t("report.role.unknown")
when UserRole::Creator
"群主"
t("report.role.creator")
when UserRole::TrustedAdmin
"受信管理员"
t("report.role.trusted_admin")
when UserRole::Admin
"管理员"
t("report.role.admin")
when UserRole::Member
"群成员"
t("report.role.member")
end
end

def make_reason(reason_value)
case Reason.new(reason_value)
when Reason::Unknown
"未记录"
t("report.reason.unknown")
when Reason::Spam
"恶意散播广告"
t("report.reason.spam")
when Reason::Halal
"未识别的清真"
t("report.reason.halal")
end
end

def make_status(status_value)
case Status.new(status_value)
when Status::Unknown
"不明"
t("report.status.unknown")
when Status::Begin
"表决中"
t("report.status.begin")
when Status::Reject
"不受理"
t("report.status.reject")
when Status::Accept
"被处理"
t("report.status.accept")
when Status::Unban
"通过申诉"
t("report.status.unban")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/policr/commanders/report.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Policr

markup << [btn.call(t("report.mass_ad"), ReportReason::Spam)]
markup << [btn.call(t("report.unident_halal"), ReportReason::Halal)]
text = t "report.admin_reply", {user_id: target_user_id}
text = t "report.admin_reply", {user_id: target_user_id, voting_channel: bot.voting_channel}
bot.send_message(
msg.chat.id, text: text,
reply_to_message_id: msg.message_id,
Expand Down
2 changes: 1 addition & 1 deletion src/policr/handlers/self_join.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Policr
Button.new(text: text, callback_data: "SelfJoin:#{item}")
}
markup << [make_btn.call t("add_to_group.leave"), "leave"]
markup << [Button.new(text: "订阅更新", url: "https://t.me/policr_changelog")]
markup << [Button.new(text: t("add_to_group.subscription_update"), url: "https://t.me/policr_changelog")]
if (user = msg.from)
user_data = {name: bot.display_name(user), user_id: user.id}
is_admin = bot.is_admin?(chat_id, user.id)
Expand Down
Loading

0 comments on commit 3dc15e8

Please sign in to comment.