mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Merge pull request #3 from CrazyHackGUT/feature/rules
/rules & /setrules commands
This commit is contained in:
@@ -33,7 +33,7 @@ jobs:
|
|||||||
name: Build and push
|
name: Build and push
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v2
|
||||||
with:
|
with:
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64
|
||||||
push: ${{ github.ref == 'refs/heads/dev' }}
|
push: ${{ github.ref == 'refs/heads/dev' }}
|
||||||
tags: ${{ secrets.REGISTRY_URL }}/west/telegram-bot:latest,
|
tags: ${{ secrets.REGISTRY_URL }}/west/telegram-bot:latest,
|
||||||
${{ secrets.REGISTRY_URL }}/west/telegram-bot:${{ steps.commit_sha.outputs.sha_short }}
|
${{ secrets.REGISTRY_URL }}/west/telegram-bot:${{ steps.commit_sha.outputs.sha_short }}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using BotFramework.Attributes;
|
||||||
|
using BotFramework.Enums;
|
||||||
|
using Kruzya.TelegramBot.Core.Data;
|
||||||
|
using Kruzya.TelegramBot.Core.Extensions;
|
||||||
|
using Telegram.Bot;
|
||||||
|
using Telegram.Bot.Exceptions;
|
||||||
|
|
||||||
|
namespace West.TelegramBot.ChatManagement.Handler
|
||||||
|
{
|
||||||
|
internal class Rules : ManagementHandler
|
||||||
|
{
|
||||||
|
[Command(InChat.Public, "setrules", CommandParseMode.Both)]
|
||||||
|
public async Task HandleSetRules()
|
||||||
|
{
|
||||||
|
var replyToMessage = Message?.ReplyToMessage;
|
||||||
|
|
||||||
|
if (replyToMessage == null || !await CanPunish()) return;
|
||||||
|
|
||||||
|
var opt = await Db.UserValues.FindOrCreateOption(Chat.Id, "rulesMsgId");
|
||||||
|
opt.SetValue(replyToMessage.MessageId);
|
||||||
|
Db.MarkAsModified(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.MarkAsDeleted(opt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rules(CoreContext db) : base(db) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user