Skip to content

Commit

Permalink
feat: allow cc to reply message
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Nov 4, 2024
1 parent 6a27113 commit 51ba28b
Show file tree
Hide file tree
Showing 131 changed files with 1,397 additions and 818 deletions.
44 changes: 22 additions & 22 deletions pmcenter/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,31 @@ dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =
dotnet_naming_symbols.non_field_members.required_modifiers =

# 命名样式

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
csharp_using_directive_placement = outside_namespace:silent
csharp_style_expression_bodied_methods = false:silent
Expand Down Expand Up @@ -161,31 +161,31 @@ dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.style = 帕斯

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.interface.required_modifiers =
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.类型.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.类型.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.类型.required_modifiers =
dotnet_naming_symbols.类型.required_modifiers =

dotnet_naming_symbols.非字段成员.applicable_kinds = property, event, method
dotnet_naming_symbols.非字段成员.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.非字段成员.required_modifiers =
dotnet_naming_symbols.非字段成员.required_modifiers =

# 命名样式

dotnet_naming_style.以_i_开始.required_prefix = I
dotnet_naming_style.以_i_开始.required_suffix =
dotnet_naming_style.以_i_开始.word_separator =
dotnet_naming_style.以_i_开始.required_suffix =
dotnet_naming_style.以_i_开始.word_separator =
dotnet_naming_style.以_i_开始.capitalization = pascal_case

dotnet_naming_style.帕斯卡拼写法.required_prefix =
dotnet_naming_style.帕斯卡拼写法.required_suffix =
dotnet_naming_style.帕斯卡拼写法.word_separator =
dotnet_naming_style.帕斯卡拼写法.required_prefix =
dotnet_naming_style.帕斯卡拼写法.required_suffix =
dotnet_naming_style.帕斯卡拼写法.word_separator =
dotnet_naming_style.帕斯卡拼写法.capitalization = pascal_case

dotnet_naming_style.帕斯卡拼写法.required_prefix =
dotnet_naming_style.帕斯卡拼写法.required_suffix =
dotnet_naming_style.帕斯卡拼写法.word_separator =
dotnet_naming_style.帕斯卡拼写法.required_prefix =
dotnet_naming_style.帕斯卡拼写法.required_suffix =
dotnet_naming_style.帕斯卡拼写法.word_separator =
dotnet_naming_style.帕斯卡拼写法.capitalization = pascal_case

[*.{cs,vb}]
Expand Down
42 changes: 26 additions & 16 deletions pmcenter/BotCommands/AutoSaveCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public async Task<bool> ExecuteAsync(TelegramBotClient botClient, Update update)
{
try
{
var text = update.Message.Text;
var interval = 30000;
string text = update.Message.Text;
int interval = 30000;
if (text.Contains(" "))
{
var command = text.Split(' ', 2)[1];
string command = text.Split(' ', 2)[1];
if (command.ToLower() == "off")
{
Vars.CurrentConf.ConfSyncInterval = 0;
Expand All @@ -32,30 +32,40 @@ public async Task<bool> ExecuteAsync(TelegramBotClient botClient, Update update)
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
if (Vars.SyncConf != null) Vars.SyncConf.Interrupt();
if (Vars.SyncConf != null)
{
Vars.SyncConf.Interrupt();
}

return true;
}

interval = int.Parse(command);
}

Vars.CurrentConf.ConfSyncInterval = interval;
_ = await botClient.SendTextMessageAsync(update.Message.From.Id,
Vars.CurrentLang.Message_AutoSaveEnabled.Replace("$1", (interval / 1000).ToString()),
parseMode: ParseMode.Markdown,
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
if (interval < 5000)
{
_ = await botClient.SendTextMessageAsync(update.Message.From.Id,
Vars.CurrentLang.Message_AutoSaveIntervalTooShort.Replace("$1", interval.ToString()),
parseMode: ParseMode.Markdown,
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
if ((Vars.SyncConf == null) || !Vars.SyncConf.IsAlive)
Vars.CurrentLang.Message_AutoSaveIntervalTooShort.Replace("$1", interval.ToString()),
parseMode: ParseMode.Markdown,
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
}

if (Vars.SyncConf == null || !Vars.SyncConf.IsAlive)
{
Vars.SyncConf = new Thread(() => Methods.ThrSyncConf());
Vars.SyncConf.Start();
}

return true;
}
catch (Exception ex)
Expand All @@ -64,9 +74,9 @@ public async Task<bool> ExecuteAsync(TelegramBotClient botClient, Update update)
_ = await botClient.SendTextMessageAsync(update.Message.From.Id,
Vars.CurrentLang.Message_GeneralFailure.Replace("$1", ex.ToString()),
parseMode: ParseMode.Markdown,
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
return true;
}
}
Expand Down
11 changes: 6 additions & 5 deletions pmcenter/BotCommands/BackupConfCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Telegram.Bot.Types.Enums;
using static pmcenter.Methods;
using static pmcenter.Methods.Logging;
using File = System.IO.File;

namespace pmcenter.Commands
{
Expand All @@ -17,16 +18,16 @@ internal class BackupConfCommand : IBotCommand

public async Task<bool> ExecuteAsync(TelegramBotClient botClient, Update update)
{
var randomFilename = $"pmcenter.{DateTime.Now:yyyy-dd-M-HH-mm-ss}#{GetRandomString(6)}.json";
string randomFilename = $"pmcenter.{DateTime.Now:yyyy-dd-M-HH-mm-ss}#{GetRandomString(6)}.json";
Log($"Backing up configurations, filename: {Path.Combine(Vars.AppDirectory, randomFilename)}", "BOT");
System.IO.File.Copy(Vars.ConfFile, randomFilename);
File.Copy(Vars.ConfFile, randomFilename);
_ = await botClient.SendTextMessageAsync(
update.Message.From.Id,
Vars.CurrentLang.Message_BackupComplete.Replace("$1", randomFilename),
parseMode: ParseMode.Markdown,
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
return true;
}
}
Expand Down
11 changes: 7 additions & 4 deletions pmcenter/BotCommands/BanCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ internal class BanCommand : IBotCommand

public async Task<bool> ExecuteAsync(TelegramBotClient botClient, Update update)
{
if (update.Message.ReplyToMessage == null || update.Message.ReplyToMessage.ForwardFrom == null) return false;
if (update.Message.ReplyToMessage == null || update.Message.ReplyToMessage.ForwardFrom == null)
{
return false;
}

BanUser(update.Message.ReplyToMessage.ForwardFrom.Id);
_ = await Conf.SaveConf(false, true).ConfigureAwait(false);
_ = await botClient.SendTextMessageAsync(
update.Message.From.Id,
Vars.CurrentLang.Message_UserBanned,
parseMode: ParseMode.Markdown,
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
return true;
}
}
Expand Down
13 changes: 7 additions & 6 deletions pmcenter/BotCommands/BanIdCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@ public async Task<bool> ExecuteAsync(TelegramBotClient botClient, Update update)
update.Message.From.Id,
Vars.CurrentLang.Message_UserBanned,
parseMode: ParseMode.Markdown,
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
}
catch (Exception ex)
{
_ = await botClient.SendTextMessageAsync(
update.Message.From.Id,
Vars.CurrentLang.Message_GeneralFailure.Replace("$1", ex.Message),
parseMode: ParseMode.Markdown,
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
}

return true;
}
}
Expand Down
46 changes: 23 additions & 23 deletions pmcenter/BotCommands/CatConfigCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Threading.Tasks;
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
Expand All @@ -14,40 +15,39 @@ internal class CatConfigCommand : IBotCommand

public async Task<bool> ExecuteAsync(TelegramBotClient botClient, Update update)
{
var text = SerializeCurrentConf();
var texts = StrChunk(text, 1024);
string text = SerializeCurrentConf();
List<string> texts = StrChunk(text, 1024);
if (texts.Count == 1)
{
_ = await botClient.SendTextMessageAsync(
update.Message.From.Id,
Vars.CurrentLang.Message_CurrentConf.Replace("$1", text),
parseMode: ParseMode.Markdown,
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
return true;
}
else

_ = await botClient.SendTextMessageAsync(
update.Message.From.Id,
Vars.CurrentLang.Message_CurrentConf.Replace("$1", texts[0]),
parseMode: ParseMode.Markdown,
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
for (int i = 1; i < texts.Count; i++)
{
_ = await botClient.SendTextMessageAsync(
update.Message.From.Id,
Vars.CurrentLang.Message_CurrentConf.Replace("$1", texts[0]),
parseMode: ParseMode.Markdown,
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
for (int i = 1; i < texts.Count; i++)
{
_ = await botClient.SendTextMessageAsync(
update.Message.From.Id,
($"`{texts[i]}`"),
parseMode: ParseMode.Markdown,
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
}
return true;
$"`{texts[i]}`",
parseMode: ParseMode.Markdown,
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
}

return true;
}
}
}
22 changes: 12 additions & 10 deletions pmcenter/BotCommands/ChatCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public async Task<bool> ExecuteAsync(TelegramBotClient botClient, Update update)
// no argument detected / use reply message instead
if (update.Message.ReplyToMessage.ForwardFrom == null)
{
throw (new ArgumentException("Cannot initiate Continued Conversation by channel posts."));
throw new ArgumentException("Cannot initiate Continued Conversation by channel posts.");
}

realTarget = update.Message.ReplyToMessage.ForwardFrom.Id;
}

Expand All @@ -50,15 +51,16 @@ public async Task<bool> ExecuteAsync(TelegramBotClient botClient, Update update)
}
else
{
replacementText = $"[{update.Message.ReplyToMessage.ForwardFrom.FirstName} (@{update.Message.ReplyToMessage.ForwardFrom.Username})](tg://user?id={realTarget})";
replacementText =
$"[{update.Message.ReplyToMessage.ForwardFrom.FirstName} (@{update.Message.ReplyToMessage.ForwardFrom.Username})](tg://user?id={realTarget})";
}

_ = await botClient.SendTextMessageAsync(update.Message.From.Id,
Vars.CurrentLang.Message_ContinuedChatEnabled.Replace("$1", replacementText),
parseMode: ParseMode.Markdown,
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
Vars.CurrentLang.Message_ContinuedChatEnabled.Replace("$1", replacementText),
parseMode: ParseMode.Markdown,
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
return true;
}
catch (Exception ex)
Expand All @@ -67,9 +69,9 @@ public async Task<bool> ExecuteAsync(TelegramBotClient botClient, Update update)
_ = await botClient.SendTextMessageAsync(update.Message.From.Id,
Vars.CurrentLang.Message_GeneralFailure.Replace("$1", ex.ToString()),
parseMode: ParseMode.Markdown,
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
linkPreviewOptions: false,
disableNotification: Vars.CurrentConf.DisableNotifications,
replyParameters: update.Message.MessageId).ConfigureAwait(false);
return true;
}
}
Expand Down
Loading

0 comments on commit 51ba28b

Please sign in to comment.