Skip to content

Commit 090d0d2

Browse files
committed
All changes from CPU local branch
1 parent 29764c8 commit 090d0d2

File tree

4 files changed

+61
-16
lines changed

4 files changed

+61
-16
lines changed

ToDo.txt

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Have a cmd to configure how long messages should stay
99
Add wikis for each command on GitHub
1010
Check if a message to reformat has something after the ```, consider the ``` the end of the block to reformat
1111

12+
Keep the last poster from each channel, and use it for te "thanks" in case there is no mention
13+
14+
1215
Errors DelAnsw EmbedRes TryCatch Log@Begin UseSQL
1316
MemberTracking | | | | X | | |
1417
Appreciation | | | | X | X | X |

UPBot Code/Actions/AppreciationTracking.cs

+39-8
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,44 @@ public async Task ShowAppreciationCommand(CommandContext ctx) {
7373
}
7474
}
7575

76+
77+
private static Dictionary<ulong, LastPosters> LastMemberPerChannels = null;
78+
79+
internal static void InitChannelList() {
80+
IReadOnlyDictionary<ulong, DiscordChannel> channels = Utils.GetGuild().Channels;
81+
LastMemberPerChannels = new Dictionary<ulong, LastPosters>();
82+
foreach (ulong cid in channels.Keys)
83+
LastMemberPerChannels[cid] = new LastPosters();
84+
}
85+
7686
internal static Task ThanksAdded(DiscordClient sender, MessageCreateEventArgs args) {
7787
try {
7888
string msg = args.Message.Content.ToLowerInvariant();
89+
ulong memberid = args.Message.Author.Id;
90+
ulong channelid = args.Message.ChannelId;
91+
if (LastMemberPerChannels == null) InitChannelList();
92+
LastPosters lp = LastMemberPerChannels[channelid];
93+
lp.Add(memberid);
94+
7995
if (thanks.IsMatch(msg) || thankyou.IsMatch(msg) || thank2you.IsMatch(msg)) { // Add thanks
8096
if (thank4n.IsMatch(msg)) return Task.FromResult(0);
8197
if (GetTracking()) return Task.FromResult(0);
8298

8399
DiscordMessage theMsg = args.Message;
84100
ulong authorId = theMsg.Author.Id;
85101
if (theMsg.Reference == null && (theMsg.MentionedUsers == null || theMsg.MentionedUsers.Count == 0)) {
86-
// Unrelated thank you, get the previous message and check
87-
IReadOnlyList<DiscordMessage> msgs = theMsg.Channel.GetMessagesBeforeAsync(theMsg.Id, 2).Result;
88-
theMsg = null;
89-
foreach (DiscordMessage m in msgs)
90-
if (m.Author.Id != authorId) {
91-
theMsg = m;
92-
break;
93-
}
102+
if (lp.secondLast != 0 || lp.secondLast != 875701548301299743ul)
103+
tracking.AlterThankYou(lp.secondLast);
104+
else {
105+
// Unrelated thank you, get the previous message and check /*
106+
IReadOnlyList<DiscordMessage> msgs = theMsg.Channel.GetMessagesBeforeAsync(theMsg.Id, 2).Result;
107+
theMsg = null;
108+
foreach (DiscordMessage m in msgs)
109+
if (m.Author.Id != authorId) {
110+
theMsg = m;
111+
break;
112+
}
113+
}
94114
if (theMsg == null) return Task.FromResult(0);
95115
}
96116

@@ -111,7 +131,18 @@ internal static Task ThanksAdded(DiscordClient sender, MessageCreateEventArgs ar
111131
}
112132

113133

134+
internal class LastPosters {
135+
public ulong thirdLast;
136+
public ulong secondLast;
137+
public ulong last;
114138

139+
internal void Add(ulong memberid) {
140+
if (last == memberid) return;
141+
thirdLast = secondLast;
142+
secondLast = last;
143+
last = memberid;
144+
}
145+
}
115146

116147

117148

UPBot Code/Database.cs

+9-7
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ public class Database {
1111

1212

1313
public static void InitDb() {
14-
// Do we have the db?
15-
if (File.Exists("Database/BotDb.db"))
16-
connection = new SQLiteConnection("Data Source=Database/" + DbName + ".db; Version=3; Journal Mode=Off; UTF8Encoding=True;"); // Open the database
17-
else
18-
connection = new SQLiteConnection("Data Source=Database/" + DbName + ".db; Version=3; Journal Mode=Off; New=True; UTF8Encoding=True;"); // Create a new database
19-
20-
// Open the connection
2114
try {
15+
// Do we have the db?
16+
if (File.Exists("Database/BotDb.db"))
17+
connection = new SQLiteConnection("Data Source=Database/" + DbName + ".db; Version=3; Journal Mode=Off; UTF8Encoding=True;"); // Open the database
18+
else {
19+
if (!Directory.Exists("Database")) Directory.CreateDirectory("Database");
20+
connection = new SQLiteConnection("Data Source=Database/" + DbName + ".db; Version=3; Journal Mode=Off; New=True; UTF8Encoding=True;"); // Create a new database
21+
}
22+
23+
// Open the connection
2224
connection.Open();
2325
Console.WriteLine("DB connection open");
2426
} catch (Exception ex) {

UPBot Code/Program.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Reflection;
45
using System.Threading.Tasks;
56
using DSharpPlus;
67
using DSharpPlus.CommandsNext;
8+
using DSharpPlus.Entities;
79
using DSharpPlus.Interactivity;
810
using DSharpPlus.Interactivity.Extensions;
911

1012
namespace UPBot {
1113
class Program {
1214
static StreamWriter lw = null;
1315
static void Main(string[] args) {
16+
17+
18+
1419
lw = File.CreateText(args.Length >= 3 ? args[2] : "debug.log");
1520
lw.WriteLine("Log Started. Woho.");
1621
lw.Flush();
@@ -92,5 +97,9 @@ static async Task MainAsync(string token, string prefix) {
9297
await Task.Delay(-1);
9398
}
9499

100+
101+
95102
}
96-
}
103+
104+
}
105+

0 commit comments

Comments
 (0)