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.Linq;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using ChaosBot.ConfigHelpers;
using ChaosBot.Models; using ChaosBot.Models;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
@ -118,8 +119,32 @@ namespace ChaosBot.Discord.Services
await dbContext.ExperiencePoints.Upsert(newUser) await dbContext.ExperiencePoints.Upsert(newUser)
.On(x => new {x.DiscordGuildId, x.DiscordUserId}).RunAsync(); .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<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) catch (Exception ex)
{ {
@ -178,8 +203,32 @@ namespace ChaosBot.Discord.Services
await dbContext.Points.Upsert(usrPoint) await dbContext.Points.Upsert(usrPoint)
.On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync(); .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<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) catch (Exception ex)
{ {