Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.

Commit 23e4ecf

Browse files
committed
Many bug fixes
- Bot will now tell you how much time it takes to assign roles - Roles are now properly removed from the roles that need to be assigned - Roles with '+' won't be incorrectly removed when checked against roleGroups.json - UserIDs is disabled (integration not completed) - Count on a new/updated readme by the end of the week. :)
1 parent 218ad71 commit 23e4ecf

File tree

4 files changed

+57
-43
lines changed

4 files changed

+57
-43
lines changed

DiscordBot/DiscordBot.csproj

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
<FileAlignment>512</FileAlignment>
1313
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1414
<IsWebBootstrapper>false</IsWebBootstrapper>
15-
<PublishUrl>publish\</PublishUrl>
15+
<NuGetPackageImportStamp>
16+
</NuGetPackageImportStamp>
17+
<PublishUrl>D:\Standard Files\Desktop\</PublishUrl>
1618
<Install>true</Install>
1719
<InstallFrom>Disk</InstallFrom>
1820
<UpdateEnabled>false</UpdateEnabled>
@@ -22,19 +24,18 @@
2224
<UpdatePeriodically>false</UpdatePeriodically>
2325
<UpdateRequired>false</UpdateRequired>
2426
<MapFileExtensions>true</MapFileExtensions>
25-
<ApplicationRevision>2</ApplicationRevision>
26-
<ApplicationVersion>0.1.3.%2a</ApplicationVersion>
27+
<AutorunEnabled>true</AutorunEnabled>
28+
<ApplicationRevision>0</ApplicationRevision>
29+
<ApplicationVersion>0.2.1.0</ApplicationVersion>
2730
<UseApplicationTrust>false</UseApplicationTrust>
2831
<PublishWizardCompleted>true</PublishWizardCompleted>
2932
<BootstrapperEnabled>true</BootstrapperEnabled>
30-
<NuGetPackageImportStamp>
31-
</NuGetPackageImportStamp>
3233
</PropertyGroup>
3334
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
3435
<PlatformTarget>AnyCPU</PlatformTarget>
3536
<DebugSymbols>true</DebugSymbols>
3637
<DebugType>full</DebugType>
37-
<Optimize>false</Optimize>
38+
<Optimize>true</Optimize>
3839
<OutputPath>bin\Debug\</OutputPath>
3940
<DefineConstants>DEBUG;TRACE</DefineConstants>
4041
<ErrorReport>prompt</ErrorReport>
@@ -57,7 +58,7 @@
5758
<TargetZone>LocalIntranet</TargetZone>
5859
</PropertyGroup>
5960
<PropertyGroup>
60-
<GenerateManifests>false</GenerateManifests>
61+
<GenerateManifests>true</GenerateManifests>
6162
</PropertyGroup>
6263
<PropertyGroup>
6364
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>

DiscordBot/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Form2Role Bot v0.0.0 -> v0.1.3 created by Talios0 (August 4th, 2018)
2-
* Form2Role Bot v0.2.0 created by Talios0 (Charles), dsong175 (Daniel), and Lawrence-O (Lawrence)
2+
* Form2Role Bot v0.2.0 and v0.2.1 created by Talios0 (Charles), dsong175 (Daniel), and Lawrence-O (Lawrence)
33
* Check the project out on Github: https://github.com/talios0/Form2RoleBot
44
* This program uses Newtonsoft's JSON, RogueExceptions' Discord.NET, and Google Sheets API v4
55
*/
@@ -16,7 +16,7 @@ internal class Program
1616
private DiscordSocketClient _client;
1717
private CommandHandler _handler;
1818

19-
private const string Version = "0.2.0";
19+
private const string Version = "0.2.1";
2020

2121
private static void Main(string[] args)
2222
=> new Program().StartAsync(args).GetAwaiter().GetResult();
@@ -26,7 +26,7 @@ public async Task StartAsync(string[] args)
2626
Console.WriteLine("---------------------------------------------------------------------");
2727
Console.WriteLine("Form2Role Bot v" + Version);
2828
Console.WriteLine("Originally Created by Talios0");
29-
Console.WriteLine("Newest version created by Talios0 (Charles), dsong175 (Daniel), and Lawrence-O (Lawrence)");
29+
Console.WriteLine("v0.2.0 and v0.2.1 created by Talios0 (Charles), dsong175 (Daniel), and Lawrence-O (Lawrence)");
3030
Console.WriteLine("Check for updates at https://github.com/talios0/Form2RoleBot/releases");
3131
Console.WriteLine("----------------------------------------------------------------------\n\n");
3232

@@ -51,7 +51,7 @@ public async Task StartAsync(string[] args)
5151
await _handler.InitializeAsync(_client);
5252

5353

54-
await Task.Delay(500); // delay so update roles doesn't run before connecting to server.
54+
await Task.Delay(750); // delay so update roles doesn't run before connecting to the server.
5555

5656
Console.WriteLine("\n");
5757
await Sheets.UpdateRoles(_client); // forces update initially on all servers

DiscordBot/Sheets.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Linq;
45
using System.Threading.Tasks;
56
using Discord.WebSocket;
@@ -38,8 +39,7 @@ public static async Task UpdateRoles(DiscordSocketClient client)
3839

3940
private static async Task AssignRoles(DiscordSocketClient client, IList<IList<Object>> values)
4041
{
41-
int startTime = DateTime.Now.Millisecond;
42-
Console.WriteLine(startTime);
42+
Stopwatch time = Stopwatch.StartNew();
4343
if (values != null && values.Count > 0)
4444
{
4545
foreach (SocketGuild g in client.Guilds) // Updates for every guild the bot is registered in. Take note that this will quickly hit a discord limit. This is fine, it will resume after a few seconds.
@@ -81,11 +81,6 @@ private static async Task AssignRoles(DiscordSocketClient client, IList<IList<Ob
8181
if (redo) redoUsers.Add(u, row);
8282

8383
// Add Roles To User
84-
foreach(SocketRole s in formattedRoles)
85-
{
86-
Console.WriteLine("Assigning: " + s.Name);
87-
}
88-
8984
await SheetsFunctionality.AddRolesToUser(u, formattedRoles.ToArray());
9085

9186
// Find and set nickname
@@ -98,8 +93,10 @@ private static async Task AssignRoles(DiscordSocketClient client, IList<IList<Ob
9893
}
9994

10095
}
101-
int endTime = DateTime.Now.Millisecond;
102-
Console.WriteLine(endTime - startTime);
96+
//DateTime endTime = DateTime.Now - startTime;
97+
//TimeSpan span = TimeSpan.
98+
time.Stop();
99+
Console.WriteLine(time.ElapsedMilliseconds + "ms\n");
103100
}
104101

105102
public static async Task AssignNewRoles(SocketGuild guild, Dictionary<SocketGuildUser,IList<object>> users)

DiscordBot/SheetsFunctionality.cs

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,48 @@ public static async Task<SocketRole> CreateRole(SocketGuild guild, string role)
8080
return guild.Roles.FirstOrDefault(x => x.Name == role);
8181
}
8282

83-
public static async Task MatchRoleGroups(SocketGuildUser user, string role)
83+
public static async Task MatchRoleGroups(SocketGuildUser user, string role, string actualCell)
8484
{
8585
foreach (string roleGroup in Config.RoleGroup.Groups)
8686
{
8787
foreach (SocketRole userRole in user.Roles) // Checks all roles assigned to the user
8888
{
89-
if (roleGroup.Contains(userRole.Name) && roleGroup.Contains(role)) // Checks for overlapping roles (from roleGroups.json)
89+
if (roleGroup.Contains(userRole.Name + ",") && roleGroup.Contains(role + ",") && role != userRole.Name) // Checks for overlapping roles (from roleGroups.json)
9090
{
91+
/*if (actualCell.Contains("+"))
92+
{
93+
bool match = false;
94+
string[] split = actualCell.Split('+');
95+
for (int i = 0; i < split.Length; i++)
96+
{
97+
split[i].Trim();
98+
}
99+
for (int i = 0; i < split.Length; i++)
100+
{
101+
if (userRole.Name.Equals(split[i]))
102+
{
103+
104+
} else
105+
{
106+
match = true;
107+
break;
108+
}
109+
}
110+
if (match)
111+
{
112+
Console.WriteLine("ROLE GROUP MATCH: " + userRole.Name + ", " + role);
113+
await user.RemoveRoleAsync(userRole);
114+
}
115+
} else
116+
{*/
91117
// Removes the user's current role
92-
await user.RemoveRoleAsync(userRole);
118+
if (!actualCell.Contains(userRole.Name) || !actualCell.Contains(role))
119+
{
120+
Console.WriteLine("ROLE GROUP MATCH: " + userRole.Name + ", " + role);
121+
await user.RemoveRoleAsync(userRole);
122+
}
123+
124+
//}
93125
}
94126
}
95127
}
@@ -98,7 +130,6 @@ public static async Task MatchRoleGroups(SocketGuildUser user, string role)
98130
public static async Task<List<string>> GetRoles(IList<object> userData, SocketGuildUser user)
99131
{
100132
List<string> allUserRoles = new List<string>();
101-
List<string> finalizedUserRoles = new List<string>();
102133
SocketRole[] assignedRoles = user.Roles.ToArray();
103134
for (int i = Config.GoogleData.RolesStartAfter; i < userData.Count - Config.GoogleData.RolesEndBefore; i++)
104135
{
@@ -115,30 +146,14 @@ public static async Task<List<string>> GetRoles(IList<object> userData, SocketGu
115146
{
116147
//await SheetsFunctionality.CheckAndCreateRole(g, formRole); // A new role is created if it doesn't exist (This is now done when formatting roles)
117148
//Console.WriteLine("Role removed " + formRole);
118-
await MatchRoleGroups(user, formRole); // Removes roles that interfere with each other as defined in the roleGroups.json configuration file
149+
await MatchRoleGroups(user, formRole, roleName); // Removes roles that interfere with each other as defined in the roleGroups.json configuration file
119150
}
120151

121152

122153
allUserRoles.AddRange(seperatedRoles);
123154
}
124-
//finalizedUserRoles = allUserRoles;
125-
foreach (string role in allUserRoles)
126-
{
127-
finalizedUserRoles.Add(role);
128-
}
129-
/*foreach (SocketRole assignedRole in assignedRoles)
130-
{
131-
foreach (string userRole in allUserRoles)
132-
{
133-
if (userRole == assignedRole.Name)
134-
{
135-
Console.WriteLine("REMOVING " + userRole);
136-
finalizedUserRoles.Remove(userRole);
137-
}
138-
}
139-
}*/
140-
return finalizedUserRoles;
141-
//return allUserRoles;
155+
156+
return allUserRoles;
142157
}
143158

144159

@@ -182,6 +197,7 @@ public static async Task AddRolesToUser(SocketGuildUser user, SocketRole[] roles
182197
if (user.Roles.Contains(role))
183198
{
184199
updatedRoles.Remove(role);
200+
//Console.WriteLine("Removing: " + role);
185201
}
186202
}
187203
await user.AddRolesAsync(updatedRoles);

0 commit comments

Comments
 (0)