Add ability to move welcome and goodbye messages

This commit is contained in:
Daniel_I_Am 2021-05-08 20:18:12 +02:00
parent 34e863bd54
commit 6691d18c99
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84

View File

@ -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,9 +119,33 @@ namespace ChaosBot.Discord.Services
await dbContext.ExperiencePoints.Upsert(newUser)
.On(x => new {x.DiscordGuildId, x.DiscordUserId}).RunAsync();
}
}
catch (Exception ex)
{
LoggingFacade.Exception(ex);
}
try
{
ulong channelId = ConfigurationRepository.GetValue<ulong>("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)
{
LoggingFacade.Exception(ex);
@ -178,9 +203,33 @@ namespace ChaosBot.Discord.Services
await dbContext.Points.Upsert(usrPoint)
.On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync();
}
}
catch (Exception ex)
{
LoggingFacade.Exception(ex);
}
try
{
ulong channelId = ConfigurationRepository.GetValue<ulong>("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)
{
LoggingFacade.Exception(ex);