Remove greet messages after 5 minutes

This commit is contained in:
Master Kwoth 2016-04-09 04:39:48 +02:00
parent 2c5bee9a3f
commit 62797a88f1

View File

@ -1,9 +1,9 @@
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using NadekoBot.Commands; using NadekoBot.Commands;
using NadekoBot.Extensions;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
/* Voltana's legacy /* Voltana's legacy
public class AsyncLazy<T> : Lazy<Task<T>> public class AsyncLazy<T> : Lazy<Task<T>>
@ -60,13 +60,20 @@ namespace NadekoBot.Modules.Administration.Commands
try try
{ {
await e.User.SendMessage($"`Farewell Message From {e.Server?.Name}`\n" + msg); await e.User.SendMessage($"`Farewell Message From {e.Server?.Name}`\n" + msg);
} }
catch { } catch { }
} }
else { else
{
if (channel == null) return; if (channel == null) return;
Greeted++; Greeted++;
await channel.Send(msg); var toDelete = await channel.SendMessage(msg);
if (e.Server.CurrentUser.GetPermissions(channel).ManageMessages)
{
await Task.Delay(300000); // 5 minutes
await toDelete.Delete();
}
} }
} }
catch { } catch { }
@ -90,10 +97,16 @@ namespace NadekoBot.Modules.Administration.Commands
Greeted++; Greeted++;
await e.User.SendMessage($"`Welcome Message From {e.Server.Name}`\n" + msg); await e.User.SendMessage($"`Welcome Message From {e.Server.Name}`\n" + msg);
} }
else { else
{
if (channel == null) return; if (channel == null) return;
Greeted++; Greeted++;
await channel.Send(msg); var toDelete = await channel.SendMessage(msg);
if (e.Server.CurrentUser.GetPermissions(channel).ManageMessages)
{
await Task.Delay(300000); // 5 minutes
await toDelete.Delete();
}
} }
} }
catch { } catch { }
@ -164,7 +177,8 @@ namespace NadekoBot.Modules.Administration.Commands
{ {
return Bye = false; return Bye = false;
} }
else { else
{
ByeChannel = id; ByeChannel = id;
return Bye = true; return Bye = true;
} }
@ -176,7 +190,8 @@ namespace NadekoBot.Modules.Administration.Commands
{ {
return Greet = false; return Greet = false;
} }
else { else
{
GreetChannel = id; GreetChannel = id;
return Greet = true; return Greet = true;
} }