Skip to content

Commit

Permalink
misc update
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Jan 29, 2023
1 parent e3ce3b4 commit b9c7c3d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish
name: publish

on:
push:
Expand Down
30 changes: 2 additions & 28 deletions XinjingdailyBot.Infrastructure/Extensions/BotClientExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,6 @@ public static class BotClientExtension
{
private static readonly NLog.Logger _logger = NLog.LogManager.GetCurrentClassLogger();

/// <summary>
/// 自动选择回复方式
/// </summary>
/// <param name="botClient"></param>
/// <param name="text"></param>
/// <param name="update"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Message?> AutoReplyAsync(
this ITelegramBotClient botClient,
string text,
Update update,
CancellationToken cancellationToken = default)
{
if (update.Type == UpdateType.Message)
{
Message msg = update.Message!;
return await botClient.SendTextMessageAsync(msg.Chat.Id, text, replyToMessageId: msg.MessageId, allowSendingWithoutReply: true, cancellationToken: cancellationToken);
}
else if (update.Type == UpdateType.CallbackQuery)
{
CallbackQuery query = update.CallbackQuery!;
await botClient.AnswerCallbackQueryAsync(query.Id, text, cancellationToken: cancellationToken);
}
return null;
}

/// <summary>
/// 发送回复
/// </summary>
Expand Down Expand Up @@ -66,9 +39,10 @@ public static async Task AutoReplyAsync(
this ITelegramBotClient botClient,
string text,
CallbackQuery query,
bool showAlert = false,
CancellationToken cancellationToken = default)
{
await botClient.AnswerCallbackQueryAsync(query.Id, text, cancellationToken: cancellationToken);
await botClient.AnswerCallbackQueryAsync(query.Id, text, showAlert: showAlert, cancellationToken: cancellationToken);
}

/// <summary>
Expand Down
14 changes: 7 additions & 7 deletions XinjingdailyBot.Service/Bot/Handler/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public async Task OnQueryCommandReceived(Users dbUser, CallbackQuery query)
Message? message = query.Message;
if (message == null)
{
await _botClient.AutoReplyAsync("消息不存在", query);
await _botClient.AutoReplyAsync("消息不存在", query, true);
return;
}

Expand All @@ -316,15 +316,15 @@ public async Task OnQueryCommandReceived(Users dbUser, CallbackQuery query)
{
if (args.Length < 2 || !long.TryParse(args[1], out long userID))
{
await _botClient.AutoReplyAsync("Payload 非法", query);
await _botClient.AutoReplyAsync("Payload 非法", query, true);
await _botClient.RemoveMessageReplyMarkupAsync(message);
return;
}

//判断消息发起人是不是同一个
if (dbUser.UserID != userID)
{
await _botClient.AutoReplyAsync("这不是你的消息, 请不要瞎点", query);
await _botClient.AutoReplyAsync("这不是你的消息, 请不要瞎点", query, true);
return;
}

Expand Down Expand Up @@ -354,7 +354,7 @@ public async Task OnQueryCommandReceived(Users dbUser, CallbackQuery query)
{
errorMsg = $"{ex.GetType} {ex.Message}";

await _botClient.AutoReplyAsync(_optionsSetting.Debug ? errorMsg : "遇到内部错误", query);
await _botClient.AutoReplyAsync(_optionsSetting.Debug ? errorMsg : "遇到内部错误", query, true);
}
handled = true;
break;
Expand All @@ -367,11 +367,11 @@ public async Task OnQueryCommandReceived(Users dbUser, CallbackQuery query)
{
if (_optionsSetting.Debug)
{
await _botClient.AutoReplyAsync($"未知的命令 [{query.Data}]", query);
await _botClient.AutoReplyAsync($"未知的命令 [{query.Data}]", query, true);
}
else
{
await _botClient.AutoReplyAsync("未知的命令", query);
await _botClient.AutoReplyAsync("未知的命令", query, true);
}
}
}
Expand All @@ -389,7 +389,7 @@ private async Task CallQueryCommandAsync(Users dbUser, CallbackQuery query, Type
//权限检查
if (!dbUser.Right.HasFlag(assemblyMethod.Rights))
{
await _botClient.AutoReplyAsync("没有权限这么做", query);
await _botClient.AutoReplyAsync("没有权限这么做", query, true);
return;
}

Expand Down

0 comments on commit b9c7c3d

Please sign in to comment.