mirror of
https://github.com/Jetsparrow/karmabot.git
synced 2026-01-21 09:06:09 +03:00
Add /at set + minor fixes
This commit is contained in:
parent
846f17f59a
commit
83b35ed4fa
@ -26,6 +26,7 @@ namespace JetKarmaBot.Commands
|
|||||||
Router.SuperCommand = "at";
|
Router.SuperCommand = "at";
|
||||||
r.Add(c.GetInstance<AwardTypeManage.CreateCommand>());
|
r.Add(c.GetInstance<AwardTypeManage.CreateCommand>());
|
||||||
r.Add(c.GetInstance<AwardTypeManage.RemoveCommand>());
|
r.Add(c.GetInstance<AwardTypeManage.RemoveCommand>());
|
||||||
|
r.Add(c.GetInstance<AwardTypeManage.SetParameterCommand>());
|
||||||
r.Add(c.GetInstance<HelpCommand>());
|
r.Add(c.GetInstance<HelpCommand>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,7 @@ namespace JetKarmaBot.Commands.AwardTypeManage
|
|||||||
Required=true,
|
Required=true,
|
||||||
Type=ChatCommandArgumentType.String,
|
Type=ChatCommandArgumentType.String,
|
||||||
Description="The award to remove",
|
Description="The award to remove",
|
||||||
DescriptionID="jetkarmabot.award.cmdnamehelp"
|
DescriptionID="jetkarmabot.at.remove.awardhelp"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ namespace JetKarmaBot.Commands.AwardTypeManage
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd.Parameters.Length < 1 || cmd.Parameters.Length > 1)
|
if (cmd.Parameters.Length != 1)
|
||||||
{
|
{
|
||||||
await Client.SendTextMessageAsync(
|
await Client.SendTextMessageAsync(
|
||||||
args.Message.Chat.Id,
|
args.Message.Chat.Id,
|
||||||
@ -58,7 +58,7 @@ namespace JetKarmaBot.Commands.AwardTypeManage
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
AwardType awardType = await db.AwardTypes.FirstAsync(x => x.CommandName == cmd.Parameters[0]);
|
AwardType awardType = await db.AwardTypes.FirstOrDefaultAsync(x => x.CommandName == cmd.Parameters[0]);
|
||||||
|
|
||||||
if (awardType == null)
|
if (awardType == null)
|
||||||
{
|
{
|
||||||
|
|||||||
116
JetKarmaBot/Commands/AwardTypeManage/SetParameterCommand.cs
Normal file
116
JetKarmaBot/Commands/AwardTypeManage/SetParameterCommand.cs
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using JetKarmaBot.Models;
|
||||||
|
using JetKarmaBot.Services;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Perfusion;
|
||||||
|
using Telegram.Bot;
|
||||||
|
using Telegram.Bot.Args;
|
||||||
|
using Telegram.Bot.Types;
|
||||||
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
|
namespace JetKarmaBot.Commands.AwardTypeManage
|
||||||
|
{
|
||||||
|
public class SetParameterCommand : IChatCommand
|
||||||
|
{
|
||||||
|
public IReadOnlyCollection<string> Names => new[] { "set" };
|
||||||
|
|
||||||
|
public string Description => "Set parameter of award type.";
|
||||||
|
|
||||||
|
public string DescriptionID => "jetkarmabot.at.set.help";
|
||||||
|
[Inject] TelegramBotClient Client { get; set; }
|
||||||
|
[Inject] public KarmaContextFactory Db { get; set; }
|
||||||
|
[Inject] public Localization Locale { get; set; }
|
||||||
|
|
||||||
|
public IReadOnlyCollection<ChatCommandArgument> Arguments => new[] {
|
||||||
|
new ChatCommandArgument() {
|
||||||
|
Name="award",
|
||||||
|
Required=true,
|
||||||
|
Type=ChatCommandArgumentType.String,
|
||||||
|
Description="The award to change",
|
||||||
|
DescriptionID="jetkarmabot.at.set.awardhelp"
|
||||||
|
},
|
||||||
|
new ChatCommandArgument() {
|
||||||
|
Name="param",
|
||||||
|
Required=true,
|
||||||
|
Type=ChatCommandArgumentType.String,
|
||||||
|
Description="The parameter to change. Can be nomname, accname, symbol or desc",
|
||||||
|
DescriptionID="jetkarmabot.at.set.paramhelp"
|
||||||
|
},
|
||||||
|
new ChatCommandArgument() {
|
||||||
|
Name="value",
|
||||||
|
Required=true,
|
||||||
|
Type=ChatCommandArgumentType.String,
|
||||||
|
Description="The value to change param to.",
|
||||||
|
DescriptionID="jetkarmabot.at.set.valuehelp"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public async Task<bool> Execute(ICommandRouter route, CommandString cmd, MessageEventArgs args)
|
||||||
|
{
|
||||||
|
using (var db = Db.GetContext())
|
||||||
|
{
|
||||||
|
var currentLocale = Locale[(await db.Chats.FindAsync(args.Message.Chat.Id)).Locale];
|
||||||
|
|
||||||
|
ChatMember cm = await Client.GetChatMemberAsync(args.Message.Chat.Id, args.Message.From.Id);
|
||||||
|
if (cm.Status != ChatMemberStatus.Administrator && cm.Status != ChatMemberStatus.Creator)
|
||||||
|
{
|
||||||
|
await Client.SendTextMessageAsync(
|
||||||
|
args.Message.Chat.Id,
|
||||||
|
currentLocale["jetkarmabot.at.set.errperm"],
|
||||||
|
replyToMessageId: args.Message.MessageId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmd.Parameters.Length != 3)
|
||||||
|
{
|
||||||
|
await Client.SendTextMessageAsync(
|
||||||
|
args.Message.Chat.Id,
|
||||||
|
currentLocale["jetkarmabot.at.set.errarg"],
|
||||||
|
replyToMessageId: args.Message.MessageId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
AwardType awardType = await db.AwardTypes.FirstOrDefaultAsync(x => x.CommandName == cmd.Parameters[0]);
|
||||||
|
|
||||||
|
if (awardType == null)
|
||||||
|
{
|
||||||
|
await Client.SendTextMessageAsync(
|
||||||
|
args.Message.Chat.Id,
|
||||||
|
currentLocale["jetkarmabot.at.set.errinvcn"],
|
||||||
|
replyToMessageId: args.Message.MessageId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (cmd.Parameters[1])
|
||||||
|
{
|
||||||
|
case "nomname":
|
||||||
|
awardType.NominativeName = cmd.Parameters[2];
|
||||||
|
break;
|
||||||
|
case "accname":
|
||||||
|
awardType.AccusativeName = cmd.Parameters[2];
|
||||||
|
break;
|
||||||
|
case "symbol":
|
||||||
|
awardType.Symbol = cmd.Parameters[2];
|
||||||
|
break;
|
||||||
|
case "desc":
|
||||||
|
awardType.Description = cmd.Parameters[2];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
await Client.SendTextMessageAsync(
|
||||||
|
args.Message.Chat.Id,
|
||||||
|
currentLocale["jetkarmabot.at.set.errinvparamname"],
|
||||||
|
replyToMessageId: args.Message.MessageId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
await Client.SendTextMessageAsync(
|
||||||
|
args.Message.Chat.Id,
|
||||||
|
string.Format(currentLocale["jetkarmabot.at.set.success"], cmd.Parameters[0],
|
||||||
|
currentLocale["jetkarmabot.at.set." + cmd.Parameters[2]]),
|
||||||
|
replyToMessageId: args.Message.MessageId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -89,7 +89,7 @@ namespace JetKarmaBot.Models
|
|||||||
.WithMany(p => p.Awards)
|
.WithMany(p => p.Awards)
|
||||||
.HasForeignKey(d => d.ChatId)
|
.HasForeignKey(d => d.ChatId)
|
||||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||||
.HasConstraintName("fk_chat");
|
.HasConstraintName("a_fk_chat");
|
||||||
|
|
||||||
entity.HasOne(d => d.From)
|
entity.HasOne(d => d.From)
|
||||||
.WithMany(p => p.AwardsFrom)
|
.WithMany(p => p.AwardsFrom)
|
||||||
@ -109,7 +109,7 @@ namespace JetKarmaBot.Models
|
|||||||
entity.ToTable("awardtype");
|
entity.ToTable("awardtype");
|
||||||
|
|
||||||
entity.HasIndex(e => e.AwardTypeId)
|
entity.HasIndex(e => e.AwardTypeId)
|
||||||
.HasName("awardtypeid_UNIQUE")
|
.HasName("at_awardtypeid_UNIQUE")
|
||||||
.IsUnique();
|
.IsUnique();
|
||||||
|
|
||||||
entity.HasIndex(e => new { e.CommandName, e.ChatId })
|
entity.HasIndex(e => new { e.CommandName, e.ChatId })
|
||||||
@ -144,7 +144,7 @@ namespace JetKarmaBot.Models
|
|||||||
.WithMany(p => p.AwardTypes)
|
.WithMany(p => p.AwardTypes)
|
||||||
.HasForeignKey(d => d.ChatId)
|
.HasForeignKey(d => d.ChatId)
|
||||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||||
.HasConstraintName("fk_chat");
|
.HasConstraintName("at_fk_chat");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity<Chat>(entity =>
|
modelBuilder.Entity<Chat>(entity =>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user