Skip to content

Commit 8307c19

Browse files
authored
Merge pull request #224 from PoliNetworkOrg/master
from master to dev
2 parents c196991 + 565c62f commit 8307c19

File tree

23 files changed

+274
-242
lines changed

23 files changed

+274
-242
lines changed

.github/workflows/ci-cd.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,6 @@ jobs:
135135
git config user.email ""
136136
git add */bot-deployment.yaml
137137
git commit -m "Update image version in K8s Deployment manifests file"
138+
git config pull.rebase false # merge
138139
git pull
139140
git push origin

PoliNetworkBot_CSharp/Code/Bots/Moderation/Blacklist/Blacklist.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ internal static class Blacklist
2424
{
2525
private static readonly List<long> SpecialGroups = new() { -1001361547847, -452591994, -1001320704409 };
2626

27+
public static readonly List<long> ViaBotBanned = new() { 220030242, 99044899 };
28+
29+
2730
private static readonly List<string> BannedWords = new()
2831
{
2932
"porcodio", "dioporco", "diocane", "$ARB", "ARBITRUM"

PoliNetworkBot_CSharp/Code/Bots/Moderation/Dispatcher/CommandDispatcher.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,33 @@ public static async Task<CommandExecutionState> HelpPrivate(MessageEventArgs? e,
796796
await Help.HelpSpecific(e, sender, args);
797797
return CommandExecutionState.SUCCESSFUL;
798798
}
799+
800+
public static async Task<CommandExecutionState> PrivacyPrivate(MessageEventArgs? e, TelegramBotAbstract? telegramBotClient,
801+
string[]? args)
802+
{
803+
await DeleteMessage.DeleteIfMessageIsNotInPrivate(telegramBotClient, e?.Message);
804+
if (telegramBotClient == null)
805+
return CommandExecutionState.ERROR_DEFAULT;
806+
807+
var lang2 = new Language(new Dictionary<string, string?>
808+
{
809+
{ "it", "Puoi contattare [email protected]"},
810+
{ "en", "You can contact [email protected]"}
811+
});
812+
813+
var messageOptions = new MessageOptions
814+
{
815+
ChatId = e?.Message.Chat.Id,
816+
Text = lang2,
817+
ChatType = e?.Message.Chat.Type,
818+
Lang = e?.Message.From?.LanguageCode,
819+
ParseMode = ParseMode.Html,
820+
ReplyMarkupObject = new ReplyMarkupObject(ReplyMarkupEnum.REMOVE),
821+
Username = e?.Message.From?.Username
822+
};
823+
await telegramBotClient.SendTextMessageAsync(messageOptions);
824+
return CommandExecutionState.SUCCESSFUL;
825+
}
799826

800827
public static async Task<CommandExecutionState> ContactUs(MessageEventArgs? e,
801828
TelegramBotAbstract? telegramBotClient)

PoliNetworkBot_CSharp/Code/Bots/Moderation/Dispatcher/SwitchDispatcher.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public static class SwitchDispatcher
5050
Permission.USER,
5151
new L("en", "This Menu @args: (optional) specific command to describe", "it",
5252
"Questo menu @args: (optional) spiegazione per un comando"), null, null),
53+
54+
new Command("privacy", CommandDispatcher.PrivacyPrivate, new List<ChatType> { ChatType.Private },
55+
Permission.USER,
56+
new L("en", "Show PoliNetwork contact's information", "it",
57+
"Mostra le informazioni per contattare PoliNetwork"), null, null),
5358

5459
new Command("help_all", CommandDispatcher.HelpExtended, new List<ChatType> { ChatType.Private },
5560
Permission.USER,

PoliNetworkBot_CSharp/Code/Bots/Moderation/Generic/AddedUsersUtil.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static async Task DealWithAddedUsers(TelegramBotAbstract? telegramBotClie
2626
return;
2727

2828
var chatId = messageEventArgs.Message.Chat.Id;
29-
if (Groups.PianoDiStudi.FullLong().Equals(chatId))
29+
if (Groups.PianoDiStudi.FullLong().Equals(chatId) || Groups.ConsiglioPc.FullLong().Equals(chatId))
3030
await RestrictUser.TryMuteUsers(telegramBotClient, messageEventArgs, added,
3131
TimeSpan.FromMinutes(5));
3232
}

PoliNetworkBot_CSharp/Code/Bots/Moderation/Generic/ThreadAsyncModeration.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ public static void DoThingsAsyncBot()
3030
var t = new Thread(CheckMessagesToSend);
3131
t.Start();
3232

33-
var t2 = new Thread(CheckMessagesToDeleteAsync);
34-
t2.Start();
33+
CheckMessageToDelete();
3534

3635
var t4 = new Thread(DoBackupAndMessageStore);
3736
t4.Start();
@@ -64,6 +63,14 @@ public static void DoThingsAsyncBot()
6463
//t3.Start();
6564
}
6665

66+
private static void CheckMessageToDelete()
67+
{
68+
GlobalVariables.Bots ??= new Dictionary<long, TelegramBotAbstract?>();
69+
var telegramBotAbstracts = GlobalVariables.Bots.Keys.Select(keyBotId => GlobalVariables.Bots[keyBotId]);
70+
var threads = telegramBotAbstracts.Select(bot => new Thread(() => { CheckMessagesToDeleteAsync(bot); }));
71+
foreach (var t2 in threads) t2.Start();
72+
}
73+
6774
private static void ProgressiveLinkCheck()
6875
{
6976
try
@@ -301,13 +308,15 @@ private static void CheckAllowedMessageExpiration()
301308
return null;
302309
}
303310

304-
private static async void CheckMessagesToDeleteAsync()
311+
private static async void CheckMessagesToDeleteAsync(TelegramBotAbstract? telegramBotAbstract)
305312
{
313+
if (telegramBotAbstract == null)
314+
return;
306315
while (true)
307316
{
308317
try
309318
{
310-
await MessageDb.CheckMessageToDelete(null);
319+
await MessageDb.CheckMessageToDelete(telegramBotAbstract);
311320
}
312321
catch (Exception? e)
313322
{

PoliNetworkBot_CSharp/Code/Bots/Moderation/Generic/UsernameNameWarning.cs

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Threading.Tasks;
5-
using PoliNetworkBot_CSharp.Code.Data.Constants;
65
using PoliNetworkBot_CSharp.Code.Data.Variables;
76
using PoliNetworkBot_CSharp.Code.Enums;
87
using PoliNetworkBot_CSharp.Code.Objects;
98
using PoliNetworkBot_CSharp.Code.Objects.AbstractBot;
10-
using PoliNetworkBot_CSharp.Code.Objects.Exceptions;
119
using PoliNetworkBot_CSharp.Code.Utils;
12-
using PoliNetworkBot_CSharp.Code.Utils.Notify;
10+
using PoliNetworkBot_CSharp.Code.Utils.MessageToRemove;
1311
using Telegram.Bot.Types;
1412
using Telegram.Bot.Types.Enums;
1513
using TeleSharp.TL;
@@ -91,20 +89,18 @@ await SendUsernameWarning(telegramBotClient,
9189
e.Message.Chat.Type,
9290
usernameCheck2.GetFirstName(),
9391
usernameCheck2.GetLastName(),
94-
e.Message.NewChatMembers,
95-
e);
92+
e.Message.NewChatMembers);
9693

9794
donesomething = true;
9895
}
9996

10097
return donesomething;
10198
}
10299

103-
public static async Task SendUsernameWarning(TelegramBotAbstract? telegramBotClient,
100+
private static async Task SendUsernameWarning(TelegramBotAbstract? telegramBotClient,
104101
bool username, bool name, string? lang, string? usernameOfUser,
105102
long chatId, long? userId, long? messageId, ChatType messageChatType,
106-
string? firstName, string? lastName, IReadOnlyCollection<User>? newChatMembers,
107-
MessageEventArgs? messageEventArgs)
103+
string? firstName, string? lastName, IReadOnlyCollection<User>? newChatMembers)
108104
{
109105
var s1I = username switch
110106
{
@@ -136,7 +132,7 @@ public static async Task SendUsernameWarning(TelegramBotAbstract? telegramBotCli
136132
if (doIt)
137133
{
138134
await SendUsernameWarning2Async(telegramBotClient, s2, lang, usernameOfUser, userId,
139-
firstName, lastName, chatId, messageChatType, messageEventArgs);
135+
firstName, lastName, chatId, messageChatType);
140136
GlobalVariables.UsernameWarningDictSent[userId.Value] = DateTime.Now;
141137
}
142138
}
@@ -151,9 +147,9 @@ await RestrictUser.Mute(60 * 5, telegramBotClient, chatId, userId, messageChatTy
151147
}
152148

153149

154-
public static async Task SendUsernameWarning2Async(TelegramBotAbstract? telegramBotClient, Language s2,
150+
private static async Task SendUsernameWarning2Async(TelegramBotAbstract? telegramBotClient, Language s2,
155151
string? lang, string? usernameOfUser, long? userId, string? firstName, string? lastName,
156-
long chatId, ChatType messageChatType, MessageEventArgs? messageEventArgs)
152+
long chatId, ChatType messageChatType)
157153
{
158154
if (telegramBotClient == null)
159155
return;
@@ -172,50 +168,20 @@ public static async Task SendUsernameWarning2Async(TelegramBotAbstract? telegram
172168
var r2 = r1?.GetMessage();
173169
if (r2 == null) return;
174170

175-
var botIdValue = botid.Value;
176171
var timeUntilDelete = TimeSpan.FromMinutes(minutesWait);
177172
var timeToDelete = DateTime.Now + timeUntilDelete;
178173

179-
GlobalVariables.MessagesToDelete ??= new List<MessageToDelete>();
180174

181-
switch (r2)
182-
{
183-
case TLMessage r3:
184-
{
185-
lock (GlobalVariables.MessagesToDelete)
186-
{
187-
var toDelete = new MessageToDelete(r3, chatId, timeToDelete, botIdValue,
188-
r1?.GetChatType(), null);
189-
GlobalVariables.MessagesToDelete.Add(toDelete);
190-
191-
FileSerialization.WriteToBinaryFile(Paths.Bin.MessagesToDelete,
192-
GlobalVariables.MessagesToDelete);
193-
}
194-
195-
break;
196-
}
197-
case Message r4:
198-
{
199-
lock (GlobalVariables.MessagesToDelete)
200-
{
201-
var toDelete = new MessageToDelete(r4, chatId, timeToDelete, botIdValue,
202-
r1?.GetChatType(), null);
203-
GlobalVariables.MessagesToDelete.Add(toDelete);
204-
205-
FileSerialization.WriteToBinaryFile(Paths.Bin.MessagesToDelete,
206-
GlobalVariables.MessagesToDelete);
207-
}
175+
MessageToRemoveUtil.AddMessageToDelete(chatId, telegramBotClient, GetId(r2), timeToDelete);
176+
}
208177

209-
break;
210-
}
211-
default:
212-
{
213-
var e4 = "Attempted to add a message to be deleted in queue\n" + r2.GetType() + " " + r2;
214-
var e3 = new Exception(e4);
215-
await NotifyUtil.NotifyOwnerWithLog2(e3, telegramBotClient,
216-
EventArgsContainer.Get(messageEventArgs));
217-
return;
218-
}
219-
}
178+
private static long? GetId(object r2)
179+
{
180+
return r2 switch
181+
{
182+
TLMessage r3 => r3.Id,
183+
Message r4 => r4.MessageId,
184+
_ => null
185+
};
220186
}
221187
}

PoliNetworkBot_CSharp/Code/Bots/Moderation/SpamCheck/CheckSpam.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ public static async Task<SpamType> CheckSpamAsync(MessageEventArgs? e, TelegramB
6464
return SpamType.ALL_GOOD;
6565
}
6666

67+
68+
var s = CheckIfSpamBotMessage(e);
69+
if (s == SpamType.SPAM_LINK)
70+
return SpamType.SPAM_LINK;
71+
72+
6773
var isSpamStored = ModerationCheck.CheckIfSpamStored(e, telegramBotClient);
6874
if (isSpamStored != null)
6975
return isSpamStored.Value;
@@ -93,4 +99,16 @@ await Blacklist.Blacklist.IsSpam(e?.Message.Caption, e?.Message.Chat.Id, telegra
9399
var s2 = SpamTypeUtil.Merge(spamType1, spamType2);
94100
return s2 ?? SpamType.ALL_GOOD;
95101
}
102+
103+
private static SpamType? CheckIfSpamBotMessage(MessageEventArgs? e)
104+
{
105+
var messageViaBotId = e?.Message.ViaBot?.Id ?? e?.Message.ForwardFrom?.Id;
106+
if (messageViaBotId == null) return null;
107+
if (!Blacklist.Blacklist.ViaBotBanned.Contains(messageViaBotId.Value)) return null;
108+
return e?.Message.Chat.Id !=
109+
-1001129635578
110+
? //policazzeggio 2
111+
SpamType.SPAM_LINK
112+
: null;
113+
}
96114
}

PoliNetworkBot_CSharp/Code/Bots/Moderation/Ticket/Data/DataTicketClass.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Octokit;
55
using PoliNetworkBot_CSharp.Code.Bots.Moderation.Ticket.Model;
66
using PoliNetworkBot_CSharp.Code.Data.Constants;
7-
using PoliNetworkBot_CSharp.Code.Objects;
87
using PoliNetworkBot_CSharp.Code.Objects.AbstractBot;
98
using ProductHeaderValue = Octokit.ProductHeaderValue;
109

PoliNetworkBot_CSharp/Code/Bots/Moderation/Ticket/Utils/CreateIssue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private static void CreateLabel(string? labelIdTelegramName, TelegramBotAbstract
6161
var owner = githubInfo?.CustomOwnerGithub ?? DataTicketClass.OwnerRepo;
6262
var repo = githubInfo?.CustomRepoGithub ?? DataTicketClass.NameRepo;
6363

64-
var labelCreated = githubClient?.Issue.Labels
64+
var labelCreated = githubClient.Issue.Labels
6565
.Create(owner, repo, label).Result;
6666
}
6767
catch

0 commit comments

Comments
 (0)