Skip to content

Commit

Permalink
Merge pull request #116 from InFTord/master
Browse files Browse the repository at this point in the history
refactoring :3
  • Loading branch information
revosw authored Jul 3, 2023
2 parents e99a6ab + 509cce3 commit 5218379
Show file tree
Hide file tree
Showing 32 changed files with 777 additions and 748 deletions.
60 changes: 0 additions & 60 deletions UPBot Code/Actions/DiscordStatus.cs

This file was deleted.

230 changes: 0 additions & 230 deletions UPBot Code/Config.cs

This file was deleted.

19 changes: 0 additions & 19 deletions UPBot.csproj

This file was deleted.

2 changes: 1 addition & 1 deletion UPBot.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31424.327
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UPBot", "UPBot.csproj", "{BC7DB5DA-E2FA-4F77-8A9C-A5451977B14E}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UPBot", "src/UPBot.csproj", "{BC7DB5DA-E2FA-4F77-8A9C-A5451977B14E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
6 changes: 4 additions & 2 deletions UPBot Code/Actions/CheckSpam.cs → src/Actions/CheckSpam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
using System.Text.RegularExpressions;
using DSharpPlus;
using DSharpPlus.EventArgs;
using UPBot.UPBot_Code;

/// <summary>
/// Command used to check for false nitro links and spam links
/// author: CPU
/// </summary>
namespace UPBot {
public class CheckSpam {
readonly static Regex linkRE = new(@"http[s]?://([^/]+)/");
readonly static Regex wwwRE = new(@"^w[^\.]{0,3}.\.");
static readonly Regex linkRE = new(@"http[s]?://([^/]+)/");
static readonly Regex wwwRE = new(@"^w[^\.]{0,3}.\.");
public static DiscordUser SpamCheckTimeout = null;
readonly string[] testLinks = { "discord.com", "discordapp.com", "discord.gg",

Expand Down
60 changes: 60 additions & 0 deletions src/Actions/DiscordStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.Entities;

/// <summary>
/// Choosing Custom Status for bot! ("Playing CS:GO!")
/// author: J0nathan550
/// </summary>

namespace UPBot.DiscordRPC {
public class DiscordStatus {
struct ActivityStatus {
public string status;
public ActivityType type;
}

static async void DiscordUpdateStatusFunction(DiscordClient client, CancellationToken token) {
List<ActivityStatus> activityStatusString = new() {
new ActivityStatus { type = ActivityType.Playing, status = "Visual Studio to code algorithms!" },
new ActivityStatus { type = ActivityType.Playing, status = "a random game" },
new ActivityStatus { type = ActivityType.Playing, status = "happily with my toys" },
new ActivityStatus { type = ActivityType.Streaming, status = "the whole life" },
new ActivityStatus { type = ActivityType.Streaming, status = "a bunch of solution" },
new ActivityStatus { type = ActivityType.Streaming, status = "programming tutorials" },
new ActivityStatus { type = ActivityType.Streaming, status = "some lights in the channels" },
new ActivityStatus { type = ActivityType.ListeningTo, status = "Ode to Joy" },
new ActivityStatus { type = ActivityType.ListeningTo, status = "your complaints" },
new ActivityStatus { type = ActivityType.ListeningTo, status = "sounds in my head" },
new ActivityStatus { type = ActivityType.ListeningTo, status = "the falling rain" },
new ActivityStatus { type = ActivityType.Watching, status = "you!" },
new ActivityStatus { type = ActivityType.Watching, status = "all users" },
new ActivityStatus { type = ActivityType.Watching, status = "for nitro fakes" },
new ActivityStatus { type = ActivityType.Watching, status = "to reformat code" },
new ActivityStatus { type = ActivityType.Watching, status = "water boil" },
new ActivityStatus { type = ActivityType.Watching, status = "grass grow" },
new ActivityStatus { type = ActivityType.Competing, status = "with other bots" },
new ActivityStatus { type = ActivityType.Competing, status = "performance review" },
new ActivityStatus { type = ActivityType.Competing, status = "performance optimization" }
};

Random random = new();
while (!token.IsCancellationRequested) {
int activity = random.Next(0, activityStatusString.Count);
ActivityStatus activityStatus = activityStatusString[activity];

await client.UpdateStatusAsync(new DiscordActivity(activityStatus.status, activityStatus.type));

await Task.Delay(TimeSpan.FromSeconds(60 + random.Next(0, 180)), token);
}
}

internal static void Start(DiscordClient client) {
Task statusUpdateTask = new(() => DiscordUpdateStatusFunction(client, new CancellationToken()));
statusUpdateTask.Start();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using UPBot.UPBot_Code;
using UPBot.UPBot_Code.DataClasses;

namespace UPBot {
public class MembersTracking {
Expand All @@ -12,7 +14,7 @@ public static async Task DiscordMemberRemoved(DiscordClient _, DSharpPlus.EventA
try {
TrackChannel trackChannel = Configs.TrackChannels[args.Guild.Id];
if (trackChannel == null || trackChannel.channel == null || !trackChannel.trackLeave) return;
if (tracking == null) tracking = new Dictionary<ulong, DateTime>();
tracking ??= new Dictionary<ulong, DateTime>();

int daysJ = (int)(DateTime.Now - args.Member.JoinedAt.DateTime).TotalDays;
if (daysJ > 10000) daysJ = -1; // User is probably destroyed. So the value will be not valid
Expand Down Expand Up @@ -46,7 +48,7 @@ public static async Task DiscordMemberAdded(DiscordClient _client, DSharpPlus.Ev
try {
TrackChannel trackChannel = Configs.TrackChannels[args.Guild.Id];
if (trackChannel == null || trackChannel.channel == null || !trackChannel.trackJoin) return;
if (tracking == null) tracking = new Dictionary<ulong, DateTime>();
tracking ??= new Dictionary<ulong, DateTime>();

tracking[args.Member.Id] = DateTime.Now;
_ = SomethingAsync(trackChannel.channel, args.Member.Id, args.Member.DisplayName, args.Member.Mention, args.Guild.MemberCount);
Expand All @@ -62,7 +64,7 @@ public static async Task DiscordMemberUpdated(DiscordClient _, DSharpPlus.EventA
try {
TrackChannel trackChannel = Configs.TrackChannels[args.Guild.Id];
if (trackChannel == null || trackChannel.channel == null || !trackChannel.trackRoles) return;
if (tracking == null) tracking = new Dictionary<ulong, DateTime>();
tracking ??= new Dictionary<ulong, DateTime>();

IReadOnlyList<DiscordRole> rolesBefore = args.RolesBefore;
IReadOnlyList<DiscordRole> rolesAfter = args.RolesAfter;
Expand All @@ -79,11 +81,10 @@ public static async Task DiscordMemberUpdated(DiscordClient _, DSharpPlus.EventA
}
if (addedRole) rolesAdded.Add(r1);
}
string msgC;
string msgL;

if (rolesBefore.Count > 0 && rolesAdded.Count > 0) {
msgC = "User " + args.Member.Mention + " has the new role" + (rolesAdded.Count > 1 ? "s:" : ":");
msgL = "User \"" + args.Member.DisplayName + "\" has the new role" + (rolesAdded.Count > 1 ? "s:" : ":");
var msgC = "User " + args.Member.Mention + " has the new role" + (rolesAdded.Count > 1 ? "s:" : ":");
var msgL = "User \"" + args.Member.DisplayName + "\" has the new role" + (rolesAdded.Count > 1 ? "s:" : ":");
foreach (DiscordRole r in rolesAdded) {
msgC += r.Mention;
msgL += r.Name;
Expand Down
1 change: 1 addition & 0 deletions UPBot Code/Commands/Delete.cs → src/Commands/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using UPBot.UPBot_Code;

/// <summary>
/// This command will delete the last x messages
Expand Down
Loading

0 comments on commit 5218379

Please sign in to comment.