diff --git a/ChaosBot/Discord/Services/CommandHandler.cs b/ChaosBot/Discord/Services/CommandHandler.cs index 9d99bd5..cbf6a55 100644 --- a/ChaosBot/Discord/Services/CommandHandler.cs +++ b/ChaosBot/Discord/Services/CommandHandler.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; +using ChaosBot.ConfigHelpers; using ChaosBot.Models; using Discord; using Discord.Commands; @@ -118,8 +119,32 @@ namespace ChaosBot.Discord.Services await dbContext.ExperiencePoints.Upsert(newUser) .On(x => new {x.DiscordGuildId, x.DiscordUserId}).RunAsync(); } + } + catch (Exception ex) + { + LoggingFacade.Exception(ex); + } - await user.Guild.SystemChannel.SendMessageAsync($"{user.Username} has joined the server."); + try + { + ulong channelId = ConfigurationRepository.GetValue("AnnounceChannel:UserJoined", user.Guild.Id, 0); + + if (channelId == 0) + { + await user.Guild.SystemChannel.SendMessageAsync($"{user.Username} has joined the server."); + } + else + { + try + { + await user.Guild.GetTextChannel(channelId) + .SendMessageAsync($"{user.Username} has joined the server."); + } + catch (Exception ex) + { + LoggingFacade.Exception(ex); + } + } } catch (Exception ex) { @@ -178,8 +203,32 @@ namespace ChaosBot.Discord.Services await dbContext.Points.Upsert(usrPoint) .On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync(); } + } + catch (Exception ex) + { + LoggingFacade.Exception(ex); + } - await user.Guild.SystemChannel.SendMessageAsync($"{user.Username} has left the server."); + try + { + ulong channelId = ConfigurationRepository.GetValue("AnnounceChannel:UserLeft", user.Guild.Id, 0); + + if (channelId == 0) + { + await user.Guild.SystemChannel.SendMessageAsync($"{user.Username} has left the server."); + } + else + { + try + { + await user.Guild.GetTextChannel(channelId) + .SendMessageAsync($"{user.Username} has left the server."); + } + catch (Exception ex) + { + LoggingFacade.Exception(ex); + } + } } catch (Exception ex) {