[reputation] Move reputation to separate module.

This commit is contained in:
West14
2022-02-14 00:18:53 +02:00
parent 6f02031e65
commit a4a44198c5
20 changed files with 595 additions and 228 deletions
+33 -33
View File
@@ -1,47 +1,47 @@
using System.Threading.Tasks;
using BotFramework.Attributes;
using BotFramework.Enums;
using Kruzya.TelegramBot.Core;
using Kruzya.TelegramBot.Core.Data;
using Kruzya.TelegramBot.Core.Extensions;
using Telegram.Bot;
using Telegram.Bot.Exceptions;
namespace West.TelegramBot.ChatManagement.Handler
namespace West.TelegramBot.ChatManagement.Handler;
class Rules : CommonHandler
{
class Rules : ManagementHandler
[Command(InChat.Public, "setrules", CommandParseMode.Both)]
public async Task HandleSetRules()
{
[Command(InChat.Public, "setrules", CommandParseMode.Both)]
public async Task HandleSetRules()
{
var replyToMessage = Message?.ReplyToMessage;
var replyToMessage = Message?.ReplyToMessage;
if (replyToMessage == null || !await Bot.IsUserAdminAsync(Chat, From)) return;
if (replyToMessage == null || !await Bot.IsUserAdminAsync(Chat, From)) return;
var opt = await Db.UserValues.FindOrCreateOption(Chat.Id, "rulesMsgId");
opt.SetValue(replyToMessage.MessageId);
Db.AddOrUpdate(opt);
}
[Command(InChat.Public, "rules", CommandParseMode.Both)]
public async Task HandleRules()
{
var opt = await Db.UserValues.FindOption(Chat.Id, "rulesMsgId");
if (opt == null)
{
return;
}
try
{
await Bot.CopyMessageAsync(Chat.Id, Chat.Id, opt.GetValue<int>());
}
catch (ApiRequestException)
{
Db.UserValues.Remove(opt);
throw;
}
}
public Rules(CoreContext db) : base(db) {}
var opt = await Db.UserValues.FindOrCreateOption(Chat.Id, "rulesMsgId");
opt.SetValue(replyToMessage.MessageId);
Db.AddOrUpdate(opt);
}
[Command(InChat.Public, "rules", CommandParseMode.Both)]
public async Task HandleRules()
{
var opt = await Db.UserValues.FindOption(Chat.Id, "rulesMsgId");
if (opt == null)
{
return;
}
try
{
await Bot.CopyMessageAsync(Chat.Id, Chat.Id, opt.GetValue<int>());
}
catch (ApiRequestException)
{
Db.UserValues.Remove(opt);
throw;
}
}
public Rules(CoreContext db) : base(db) {}
}