Try-catch the timer functionality
This commit is contained in:
parent
2adc291b7d
commit
a06c6d5e91
@ -28,32 +28,43 @@ namespace ChaosBot.Discord.Services
|
|||||||
|
|
||||||
async void UpdateChannelSloganDescription()
|
async void UpdateChannelSloganDescription()
|
||||||
{
|
{
|
||||||
SocketGuild guild = _client.GetGuild(Convert.ToUInt64(serverConfig.Key));
|
try
|
||||||
if (guild == null)
|
|
||||||
{
|
{
|
||||||
_logger.Warn($"Guild {Convert.ToUInt64(serverConfig.Key)} not found");
|
SocketGuild guild = _client.GetGuild(Convert.ToUInt64(serverConfig.Key));
|
||||||
return;
|
if (guild == null)
|
||||||
}
|
{
|
||||||
|
_logger.Warn($"Guild {Convert.ToUInt64(serverConfig.Key)} not found");
|
||||||
SocketChannel socketChannel = guild.GetChannel(Convert.ToUInt64(lodestoneChannelSloganDescriptionId));
|
return;
|
||||||
if (socketChannel == null)
|
}
|
||||||
{
|
|
||||||
_logger.Warn($"Channel {Convert.ToUInt64(lodestoneChannelSloganDescriptionId)} not found in server {guild.Name}");
|
SocketChannel socketChannel =
|
||||||
return;
|
guild.GetChannel(Convert.ToUInt64(lodestoneChannelSloganDescriptionId));
|
||||||
}
|
if (socketChannel == null)
|
||||||
|
{
|
||||||
ITextChannel channel = socketChannel as ITextChannel;
|
_logger.Warn(
|
||||||
if (channel == null)
|
$"Channel {Convert.ToUInt64(lodestoneChannelSloganDescriptionId)} not found in server {guild.Name}");
|
||||||
{
|
return;
|
||||||
_logger.Warn($"Could not cast channel {socketChannel.Id} to ITextChannel");
|
}
|
||||||
return;
|
|
||||||
};
|
ITextChannel channel = socketChannel as ITextChannel;
|
||||||
|
if (channel == null)
|
||||||
|
{
|
||||||
|
_logger.Warn($"Could not cast channel {socketChannel.Id} to ITextChannel");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
string description = LodestoneManager.GetFreeCompanyById(serverConfig.GetValue<string>("Lodestone:FreeCompanyId")).FreeCompany.Slogan;;
|
if (!guild.GetUser(_client.CurrentUser.Id).GetPermissions(channel).ManageChannel) return;
|
||||||
await channel.ModifyAsync(x =>
|
|
||||||
|
string description = LodestoneManager
|
||||||
|
.GetFreeCompanyById(serverConfig.GetValue<string>("Lodestone:FreeCompanyId")).FreeCompany
|
||||||
|
.Slogan;
|
||||||
|
|
||||||
|
await channel.ModifyAsync(x => { x.Topic = description; });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
x.Topic = description;
|
_logger.Error($"TimerHandler.UpdateChannelSloganDescription: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer.RunTimer(UpdateChannelSloganDescription, new TimeSpan(TimeSpan.TicksPerMinute * refreshMinutes));
|
Timer.RunTimer(UpdateChannelSloganDescription, new TimeSpan(TimeSpan.TicksPerMinute * refreshMinutes));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user