Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Eliaxie committed Sep 10, 2023
1 parent 9186654 commit 92c0a5d
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .idea/.idea.PoliNetworkBot.dir/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using PoliNetwork.Telegram.Bot.Bots;
using Telegram.Bot;
using Telegram.Bot.Types;

Expand All @@ -15,5 +16,5 @@ public abstract class AbstractTelegramBotFunctionality : ITelegramBotFunctionali
/// <param name="update"></param>
/// <param name="cancellationToken"></param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public abstract Task RunAsync(ITelegramBotClient bot, Update update, CancellationToken cancellationToken); }
public abstract Task RunAsync(AbstractTelegramBot bot, Update update, CancellationToken cancellationToken); }
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using PoliNetwork.Telegram.Bot.Bots;
using Telegram.Bot;
using Telegram.Bot.Types;

Expand All @@ -15,6 +16,6 @@ public interface ITelegramBotFunctionality
/// <param name="update"></param>
/// <param name="cancellationToken"></param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
Task RunAsync(ITelegramBotClient bot, Update update, CancellationToken cancellationToken);
Task RunAsync(AbstractTelegramBot bot, Update update, CancellationToken cancellationToken);
}
}
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

}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Moderation.Bot.Functionality;
using Moderation.Bot.Functionality.Generic;
using PoliNetwork.Telegram.Bot.Bots;
using Telegram.Bot;
using Telegram.Bot.Types;

Expand All @@ -14,7 +15,7 @@ public DefaultUpdateHandler(List<ITelegramBotFunctionality> functionalities)
Functionalities = functionalities;
}

public async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
public async Task HandleUpdateAsync(AbstractTelegramBot botClient, Update update, CancellationToken cancellationToken)
{
/* Parallel.ForEach(_functionalities, functionalities => functionalities.Run(botClient, update, cancellationToken)); */
foreach (var functionality in Functionalities)
Expand Down
3 changes: 2 additions & 1 deletion Moderation/Moderation/src/Bot/Handler/IUpdateHandler.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using PoliNetwork.Telegram.Bot.Bots;
using Telegram.Bot;
using Telegram.Bot.Types;

Expand All @@ -15,6 +16,6 @@ public interface IUpdateHandler
/// <param name="update">The <see cref="Update"/> representing the incoming update to be handled.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that can be used to cancel the asynchronous operation.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken);
Task HandleUpdateAsync(AbstractTelegramBot botClient, Update update, CancellationToken cancellationToken);
}
}
3 changes: 2 additions & 1 deletion Moderation/Moderation/src/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ namespace Moderation
public static class Config
{
private static readonly string? BASE_PATH = Directory.GetParent(Environment.CurrentDirectory)?.FullName;
public static readonly string FORBIDDEN_WORDS = BASE_PATH + @"\Moderation\src\persistence\forbidden_words.json";
public static readonly string FORBIDDEN_WORDS = BASE_PATH + @"\Moderation\src\persistence\forbidden.json";
public static readonly string APP_SETTINGS = BASE_PATH + @"\Moderation\src\persistence\appsettings.json";
public static readonly string ROLES_DATA = BASE_PATH + @"\Moderation\src\persistence\roles.json";
}
}
22 changes: 22 additions & 0 deletions Moderation/Moderation/src/persistence/roles.json
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
}
}
1 change: 1 addition & 0 deletions Moderation/ModerationTest/ModerationTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<ProjectReference Include="..\Moderation\Lib_CSharp\PoliNetwork.Core\src\PoliNetwork.Core.csproj" />
<ProjectReference Include="..\Moderation\Lib_CSharp\PoliNetwork.Db\src\PoliNetwork.Db.csproj" />
<ProjectReference Include="..\Moderation\Lib_CSharp\PoliNetwork.Telegram\src\PoliNetwork.Telegram.csproj" />
<ProjectReference Include="..\Moderation\Lib_CSharp\PoliNetwork.Telegram\Test\PoliNetwork.Telegram.Test.csproj" />
</ItemGroup>


Expand Down

0 comments on commit 92c0a5d

Please sign in to comment.