Skip to content

Commit

Permalink
Merge pull request #84 from United-Programming/cpu_dev
Browse files Browse the repository at this point in the history
Completed V1.2
  • Loading branch information
CPULL authored Aug 26, 2021
2 parents 649237d + dea0a18 commit 6b6b822
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 141 deletions.
9 changes: 5 additions & 4 deletions ToDo.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
Have command to alter the command character [NOT POSSIBLE!]
!Check all command names
Add wikis for each command on GitHub
!Uniform all error messages with Embeds (use Duck code)
!Have all messages and commands to disappear after a while (configurable) if not needed to stay
Have a cmd to configure how long messages should stay
!Add TryCatch to all code and commands
Add "keep" option to reformat
Extend the reputation by checking "tanks and thank you" in messages and add to mentioned mebers or author of referenced message
!Extend the reputation by checking "tanks and thank you" in messages and add to mentioned mebers or author of referenced message
Have a cmd to configure how long messages should stay
!Add "delete" option to reformat
Add wikis for each command on GitHub
Check if a message to reformat has something after the ```, consider the ``` the end of the block to reformat

Errors DelAnsw EmbedRes TryCatch Log@Begin UseSQL
MemberTracking | | | | X | | |
Expand Down
25 changes: 18 additions & 7 deletions UPBot Code/Actions/AppreciationTracking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,32 @@ public async Task ShowAppreciationCommand(CommandContext ctx) {

internal static Task ThanksAdded(DiscordClient sender, MessageCreateEventArgs args) {
try {
if (args.Message.Reference == null && (args.Message.MentionedUsers == null || args.Message.MentionedUsers.Count == 0)) return Task.FromResult(0);

string msg = args.Message.Content.ToLowerInvariant();
if (thanks.IsMatch(msg) || thankyou.IsMatch(msg) || thank2you.IsMatch(msg)) { // Add thanks
if (thank4n.IsMatch(msg)) return Task.FromResult(0);
if (GetTracking()) return Task.FromResult(0);

IReadOnlyList<DiscordUser> mentions = args.Message.MentionedUsers;
ulong authorId = args.Message.Author.Id;
ulong refAuthorId = args.Message.Reference != null ? args.Message.Reference.Message.Author.Id : 0;
DiscordMessage theMsg = args.Message;
ulong authorId = theMsg.Author.Id;
if (theMsg.Reference == null && (theMsg.MentionedUsers == null || theMsg.MentionedUsers.Count == 0)) {
// Unrelated thank you, get the previous message and check
IReadOnlyList<DiscordMessage> msgs = theMsg.Channel.GetMessagesBeforeAsync(theMsg.Id, 2).Result;
theMsg = null;
foreach (DiscordMessage m in msgs)
if (m.Author.Id != authorId) {
theMsg = m;
break;
}
if (theMsg == null) return Task.FromResult(0);
}

IReadOnlyList<DiscordUser> mentions = theMsg.MentionedUsers;
ulong refAuthorId = theMsg.Reference != null ? theMsg.Reference.Message.Author.Id : 0;
if (mentions != null)
foreach (DiscordUser u in mentions)
if (u.Id != authorId && u.Id != refAuthorId) tracking.AlterThankYou(u.Id);
if (args.Message.Reference != null)
if (args.Message.Reference.Message.Author.Id != authorId) tracking.AlterThankYou(args.Message.Reference.Message.Author.Id);
if (theMsg.Reference != null)
if (theMsg.Reference.Message.Author.Id != authorId) tracking.AlterThankYou(theMsg.Reference.Message.Author.Id);
}

return Task.FromResult(0);
Expand Down
30 changes: 15 additions & 15 deletions UPBot Code/Actions/MembersTracking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ public class MembersTracking {
static DiscordChannel trackChannel = null;

public static async Task DiscordMemberRemoved(DiscordClient client, DSharpPlus.EventArgs.GuildMemberRemoveEventArgs args) {
try{
if (tracking == null) tracking = new Dictionary<ulong, DateTime>();
if (trackChannel == null) trackChannel = args.Guild.GetChannel(831186370445443104ul);
try {
if (tracking == null) tracking = new Dictionary<ulong, DateTime>();
if (trackChannel == null) trackChannel = args.Guild.GetChannel(831186370445443104ul);

if (tracking.ContainsKey(args.Member.Id)) {
tracking.Remove(args.Member.Id);
string msg = "User " + args.Member.DisplayName + " did a kiss and go.";
await trackChannel.SendMessageAsync(msg);
Utils.Log(msg);
}
else {
string msgC = Utils.GetEmojiSnowflakeID(EmojiEnum.KO) + " User " + args.Member.Mention + " left on " + DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + " (" + args.Guild.MemberCount + " memebrs total)";
string msgL = "- User " + args.Member.DisplayName + " left on " + DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + " (" + args.Guild.MemberCount + " memebrs total)";
await trackChannel.SendMessageAsync(msgC);
Utils.Log(msgL);
}
if (tracking.ContainsKey(args.Member.Id)) {
tracking.Remove(args.Member.Id);
string msg = "User " + args.Member.DisplayName + " did a kiss and go.";
await trackChannel.SendMessageAsync(msg);
Utils.Log(msg);
}
else {
string msgC = Utils.GetEmojiSnowflakeID(EmojiEnum.KO) + " User " + args.Member.Mention + " (" + args.Member.DisplayName + ") left on " + DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + " (" + args.Guild.MemberCount + " memebrs total)";
string msgL = "- User " + args.Member.DisplayName + " left on " + DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + " (" + args.Guild.MemberCount + " memebrs total)";
await trackChannel.SendMessageAsync(msgC);
Utils.Log(msgL);
}
} catch (Exception ex) {
Utils.Log("Error in DiscordMemberRemoved: " + ex.Message);
}
Expand Down
Loading

0 comments on commit 6b6b822

Please sign in to comment.