#105 Only fetch some data if it is required to generate filename

This commit is contained in:
Serraniel 2021-12-16 14:47:47 +01:00
parent 767b2b35d1
commit dccbd4ab0b
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3

View file

@ -234,19 +234,29 @@ namespace DML.AppCore.Classes
var serverName = "unknown";
string nickname = null;
if (fileName.Contains("%guildid%") || fileName.Contains("%nickname%"))
{
var socketTextChannel = message.Channel as SocketTextChannel;
if (socketTextChannel != null)
{
// fetch servername
serverName = socketTextChannel.Guild.Name;
serverName = Path.GetInvalidFileNameChars()
.Aggregate(serverName, (current, c) => current.Replace(c, ' '));
// fetch nickname
if (fileName.Contains("%nickname%"))
{
var serverUser =
socketTextChannel.GetUser(message.Author.Id); // can be null if user left the server
socketTextChannel.GetUser(message.Author
.Id); // can be null if user left the server
if (serverUser != null)
nickname = serverUser.Nickname;
}
}
}
// fetch channelname
var channelName = message.Channel.Name;
channelName = Path.GetInvalidFileNameChars()
.Aggregate(channelName, (current, c) => current.Replace(c, ' '));