mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Merge branch 'dev' of https://github.com/CrazyHackGUT/telegram-bot into dev
This commit is contained in:
@@ -37,4 +37,18 @@ public static class DbContextExtension
|
|||||||
|
|
||||||
entry.State = EntityState.Modified;
|
entry.State = EntityState.Modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void AddOrUpdate(this DbContext dbContext, object entity)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
dbContext.Update(entity);
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
}
|
||||||
|
catch (DbUpdateConcurrencyException e)
|
||||||
|
{
|
||||||
|
dbContext.Add(entity);
|
||||||
|
dbContext.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,8 +71,7 @@ namespace Kruzya.TelegramBot.Core
|
|||||||
await databaseContext.Users.AddAsync(new BotUser()
|
await databaseContext.Users.AddAsync(new BotUser()
|
||||||
{
|
{
|
||||||
ChatId = chat,
|
ChatId = chat,
|
||||||
UserId = user,
|
UserId = user
|
||||||
BotUserId = new Guid()
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ namespace West.TelegramBot.ChatManagement.Handler
|
|||||||
|
|
||||||
_logger.LogDebug("Saving receiver rep with value: {Value}", receiverRepCount);
|
_logger.LogDebug("Saving receiver rep with value: {Value}", receiverRepCount);
|
||||||
receiverRepOption.SetValue(receiverRepCount);
|
receiverRepOption.SetValue(receiverRepCount);
|
||||||
Db.Update(receiverRepOption);
|
Db.AddOrUpdate(receiverRepOption);
|
||||||
_logger.LogDebug("Updated value: {Value}", receiverRepOption.GetValue<double>());
|
_logger.LogDebug("Updated value: {Value}", receiverRepOption.GetValue<double>());
|
||||||
|
|
||||||
await Reply($"{From.ToHtml()}<code>({await GetUserReputation(From)}) " +
|
await Reply($"{From.ToHtml()}<code>({await GetUserReputation(From)}) " +
|
||||||
@@ -141,7 +141,7 @@ namespace West.TelegramBot.ChatManagement.Handler
|
|||||||
reputation = Math.Round(reputation, 2);
|
reputation = Math.Round(reputation, 2);
|
||||||
var opt = await GetReputationOption(RepliedUser);
|
var opt = await GetReputationOption(RepliedUser);
|
||||||
opt.SetValue(reputation);
|
opt.SetValue(reputation);
|
||||||
Db.Update(opt);
|
Db.AddOrUpdate(opt);
|
||||||
|
|
||||||
await Reply(
|
await Reply(
|
||||||
new HtmlString()
|
new HtmlString()
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace West.TelegramBot.ChatManagement.Handler
|
|||||||
|
|
||||||
var opt = await Db.UserValues.FindOrCreateOption(Chat.Id, "rulesMsgId");
|
var opt = await Db.UserValues.FindOrCreateOption(Chat.Id, "rulesMsgId");
|
||||||
opt.SetValue(replyToMessage.MessageId);
|
opt.SetValue(replyToMessage.MessageId);
|
||||||
Db.Update(opt);
|
Db.AddOrUpdate(opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command(InChat.Public, "rules", CommandParseMode.Both)]
|
[Command(InChat.Public, "rules", CommandParseMode.Both)]
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace West.TelegramBot.ChatManagement.Handler
|
|||||||
var warnOption = await GetWarnOption(warnUser);
|
var warnOption = await GetWarnOption(warnUser);
|
||||||
var warnCount = warnOption!.GetValue<int>() + 1;
|
var warnCount = warnOption!.GetValue<int>() + 1;
|
||||||
warnOption.SetValue(warnCount);
|
warnOption.SetValue(warnCount);
|
||||||
Db.Update(warnOption);
|
Db.AddOrUpdate(warnOption);
|
||||||
|
|
||||||
await Bot.SendTextMessageAsync(Chat.Id, $"{warnUser.ToHtml()}<code>, Вам выдано предупреждение! " +
|
await Bot.SendTextMessageAsync(Chat.Id, $"{warnUser.ToHtml()}<code>, Вам выдано предупреждение! " +
|
||||||
$"Текущее кол-во: {warnCount}/3</code>",
|
$"Текущее кол-во: {warnCount}/3</code>",
|
||||||
@@ -49,7 +49,7 @@ namespace West.TelegramBot.ChatManagement.Handler
|
|||||||
|
|
||||||
warnCount = Math.Max(warnCount - 1, 0);
|
warnCount = Math.Max(warnCount - 1, 0);
|
||||||
warnOption.SetValue(warnCount);
|
warnOption.SetValue(warnCount);
|
||||||
Db.Update(warnOption);
|
Db.AddOrUpdate(warnOption);
|
||||||
|
|
||||||
await Bot.SendTextMessageAsync(Chat.Id,
|
await Bot.SendTextMessageAsync(Chat.Id,
|
||||||
$"{RepliedUser.ToHtml()}<code>, с Вас снято предупреждение! " +
|
$"{RepliedUser.ToHtml()}<code>, с Вас снято предупреждение! " +
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace West.Entertainment.Handler.Fun
|
|||||||
|
|
||||||
var animationFileOption = await GetAnimationFileOption();
|
var animationFileOption = await GetAnimationFileOption();
|
||||||
animationFileOption.SetValue(animation.FileId);
|
animationFileOption.SetValue(animation.FileId);
|
||||||
_db.Update(animationFileOption);
|
_db.AddOrUpdate(animationFileOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReSharper disable once MemberCanBeProtected.Global
|
// ReSharper disable once MemberCanBeProtected.Global
|
||||||
@@ -77,7 +77,7 @@ namespace West.Entertainment.Handler.Fun
|
|||||||
replyToMessageId: GetMessageIdToReply() ?? Message?.MessageId);
|
replyToMessageId: GetMessageIdToReply() ?? Message?.MessageId);
|
||||||
|
|
||||||
nextUseOption.SetValue(DateTime.Now + Cooldown);
|
nextUseOption.SetValue(DateTime.Now + Cooldown);
|
||||||
_db.Update(nextUseOption);
|
_db.AddOrUpdate(nextUseOption);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace UserGroupTag
|
|||||||
tagDictionary[groupName] = memberList;
|
tagDictionary[groupName] = memberList;
|
||||||
|
|
||||||
userGroupOption.SetValue(tagDictionary);
|
userGroupOption.SetValue(tagDictionary);
|
||||||
_db.Update(userGroupOption);
|
_db.AddOrUpdate(userGroupOption);
|
||||||
|
|
||||||
_userCache.SetValue(repliedMessage.From.Id, repliedMessage.From, Int32.MaxValue);
|
_userCache.SetValue(repliedMessage.From.Id, repliedMessage.From, Int32.MaxValue);
|
||||||
await Bot.SendTextMessageAsync(chatId, $"{from.ToHtml()} добавлен в группу {groupName}",
|
await Bot.SendTextMessageAsync(chatId, $"{from.ToHtml()} добавлен в группу {groupName}",
|
||||||
|
|||||||
Reference in New Issue
Block a user