-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
65 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 29 additions & 2 deletions
31
Moderation/Moderation/src/Bot/Functionality/Implementations/CheckIfMessageIsSpam.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,46 @@ | ||
using System.Net; | ||
using Moderation.Bot.Functionality.Generic; | ||
using Moderation.Utility.Converter; | ||
using Moderation.Utility.MessageContentControl; | ||
using Moderation.Utility.SpamDetection; | ||
using Newtonsoft.Json; | ||
using PoliNetwork.Telegram.Bot.Bots; | ||
using PoliNetwork.Telegram.Bot.Functionality; | ||
using PoliNetwork.Telegram.Utility.Logger; | ||
using Telegram.Bot; | ||
using Telegram.Bot.Types; | ||
using File = System.IO.File; | ||
|
||
namespace Moderation.Bot.Functionality.Implementations | ||
{ | ||
public class CheckIfMessageIsSpam : AbstractTelegramBotFunctionality | ||
{ | ||
public override async Task RunAsync(ITelegramBotClient bot, Update update, CancellationToken cancellationToken) | ||
public AdminUtils.RoleData RoleData { get; set; } = LoadRoleData(); | ||
|
||
private static AdminUtils.RoleData LoadRoleData() | ||
{ | ||
var path = Config.ROLES_DATA; | ||
AdminUtils.RoleData? roleDataRaw = null; | ||
try | ||
{ | ||
roleDataRaw = JsonConvert.DeserializeObject<AdminUtils.RoleData>(File.ReadAllText(path)); | ||
} | ||
catch (Exception e) | ||
{ | ||
var logger = new DefaultLogger(); | ||
logger.Error("Got an exception while trying to deserialize object in ForbiddenWordsDetection"); | ||
logger.Error(e); | ||
} | ||
var forbiddenData = roleDataRaw ?? new AdminUtils.RoleData(); | ||
return forbiddenData; | ||
} | ||
|
||
public override async Task RunAsync(AbstractTelegramBot bot, Update update, CancellationToken cancellationToken) | ||
{ | ||
if (update.Message is { From: not null }) await AdminUtils.CheckIfUserIsAdmin(RoleData, update.Message.From, update.Message.Chat.Id, bot); | ||
// check if message is user is admin or global admin | ||
// check if message is spam | ||
// if message is spam, delete it | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"owners": { | ||
"name": "John Doe", | ||
"username": "", | ||
"id": 1234 | ||
}, | ||
"creators": { | ||
"name": "John Doe", | ||
"username": "", | ||
"id": 1234 | ||
}, | ||
"admins": { | ||
"name": "John Doe", | ||
"username": "", | ||
"id": 1234 | ||
}, | ||
"moderators": { | ||
"name": "John Doe", | ||
"username": "", | ||
"id": 1234 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters