Skip to content

Commit

Permalink
Slowly moving over to dependency injection. Starting with DiscordBot
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukires committed Jul 27, 2022
1 parent 650484f commit d84cbea
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Dikubot/DataLayer/Cronjob/Cronjobs/ForceNameChangeTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private static void Update()
Logger.Debug("Forcing name changes for selected servers");
GuildSettingsService guildSettingsService = new GuildSettingsService();
UserGlobalServices userGlobalServices = new UserGlobalServices();
foreach (var guild in DiscordBot.Client.Guilds)
foreach (var guild in DiscordBot.ClientStatic.Guilds)
{
GuildSettingsModel guildSettingsModel = guildSettingsService.Get(guild);
if (!guildSettingsModel.ForceNameChange)
Expand Down
2 changes: 1 addition & 1 deletion Dikubot/DataLayer/Cronjob/Cronjobs/UpdateUserRolesTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public UpdateUserRolesTask() : base(Cronos.CronExpression.Parse("0 */2 * * *"),
private static void Update()
{
Logger.Debug("Updating all user roles");
foreach (var guild in DiscordBot.Client.Guilds)
foreach (var guild in DiscordBot.ClientStatic.Guilds)
{
PermissionsService permissionsService = new PermissionsService(guild);
GuildSettingsModel guildSettingsModel = permissionsService.GetGuildSettingsService().Get(guild);
Expand Down
4 changes: 2 additions & 2 deletions Dikubot/DataLayer/Database/Global/User/UserGlobalModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public string Email
[BsonIgnore]
public IUser DiscordUser
{
get => DiscordBot.Client.GetUserAsync(DiscordIdLong).Result;
get => DiscordBot.ClientStatic.GetUserAsync(DiscordIdLong).Result;
set => DiscordId = value.Id.ToString();
}

Expand Down Expand Up @@ -65,7 +65,7 @@ public HashSet<Guid> Calendar

public SocketGuild GetSelectedGuild()
{
SocketGuild guild = DiscordBot.Client.GetGuild(SelectedGuild);
SocketGuild guild = DiscordBot.ClientStatic.GetGuild(SelectedGuild);
if (guild == null)
{
throw new Exception($"SelectedGuild ({SelectedGuild}) can't be found");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public CalendarServices(SocketGuild guild) : base("Calendar", guild)
}


public CalendarServices(string guidId) : base("Calendar", DiscordBot.Client.Guilds?.FirstOrDefault(g => g.Id.ToString().Equals(guidId)))
public CalendarServices(string guidId) : base("Calendar", DiscordBot.ClientStatic.Guilds?.FirstOrDefault(g => g.Id.ToString().Equals(guidId)))
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class EquipmentServices : GuildServices<EquipmentModel>
public EquipmentServices(SocketGuild guild) : base("Equipment", guild)
{
}
public EquipmentServices(string guidId) : base("Equipment", DiscordBot.Client.Guilds?.FirstOrDefault(g => g.Id.ToString().Equals(guidId)))
public EquipmentServices(string guidId) : base("Equipment", DiscordBot.ClientStatic.Guilds?.FirstOrDefault(g => g.Id.ToString().Equals(guidId)))
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public EventsServices(SocketGuild guild, string calendar = null) : base("Events"
}


public EventsServices(string guidId, string calendar = null) : base("Events", DiscordBot.Client.Guilds?.FirstOrDefault(g => g.Id.ToString().Equals(guidId)))
public EventsServices(string guidId, string calendar = null) : base("Events", DiscordBot.ClientStatic.Guilds?.FirstOrDefault(g => g.Id.ToString().Equals(guidId)))
{
_calendar = calendar;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class RoomServices : GuildServices<RoomModel>
public RoomServices(SocketGuild guild) : base("Room", guild)
{
}
public RoomServices(string guidId) : base("Room", DiscordBot.Client.Guilds?.FirstOrDefault(g => g.Id.ToString().Equals(guidId)))
public RoomServices(string guidId) : base("Room", DiscordBot.ClientStatic.Guilds?.FirstOrDefault(g => g.Id.ToString().Equals(guidId)))
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class UserGuildModel : MainModel
[BsonIgnore]
public SocketUser DiscordUser
{
get => DiscordBot.Client.GetUser(Convert.ToUInt64(DiscordId));
get => DiscordBot.ClientStatic.GetUser(Convert.ToUInt64(DiscordId));
set => DiscordId = value.Id.ToString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static ulong SubDomainToDiscordId(string subdomain)

public static SocketGuild GetGuildFromDomain(string domain)
{
return DiscordBot.Client.GetGuild(DomainToDiscordId(domain));
return DiscordBot.ClientStatic.GetGuild(DomainToDiscordId(domain));
}

}
Expand Down
2 changes: 1 addition & 1 deletion Dikubot/DataLayer/Static/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static string ConcatListToString<T>(List<T> list)

public static bool IsGuildAdmin(ulong userId, ulong guildId)
{
SocketGuild guild = DiscordBot.Client.GetGuild(guildId);
SocketGuild guild = DiscordBot.ClientStatic.GetGuild(guildId);
SocketGuildUser user = guild?.GetUser(userId);
return guild != null &&
(guild.OwnerId == user.Id || user.Roles.Any(role => role.Permissions.Administrator));
Expand Down
22 changes: 7 additions & 15 deletions Dikubot/Webapp/Startup.cs → Dikubot/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
using System;
using Blazored.LocalStorage;
using BlazorLoginDiscord.Data;
using Dikubot.Webapp.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Components.Authorization;
using System;
using System.Net;
using System.Threading.Tasks;
using AspNet.Security.OAuth.Discord;
using Blazored.LocalStorage;
using BlazorLoginDiscord.Data;
using Dikubot.Webapp.Authentication;
using Dikubot.Webapp.Authentication.Discord.OAuth2;
using Microsoft.AspNetCore.CookiePolicy;
using Microsoft.AspNetCore.Http;
using MudBlazor.Services;
using Syncfusion.Blazor;


namespace Dikubot.Webapp
namespace Dikubot
{
public class Startup
{
Expand Down

0 comments on commit d84cbea

Please sign in to comment.