Ejemplo n.º 1
0
        protected override async Task _Invoke(MessageContext context)
        {
            var channelId = context.MessageEvent.Channel.Id;

            if (!EphemeralData.ContainsId(channelId))
            {
                await context.Reply("This channel is already non-ephemeral").ConfigureAwait(false);

                return;
            }

            var            messageId = context.MessageEvent.Message.Id;
            DiscordMessage reply;

            if (EphemeralData.Remove(channelId))
            {
                reply = await context.Reply("This channel is no longer ephemeral.").ConfigureAwait(false);
            }
            else
            {
                reply = await context.Reply(":x: Error: could not mark this channel as non-ephemeral.").ConfigureAwait(false);
            }

            EphemeralContext.NoDeleteMessageIdSet.Add(messageId);
            EphemeralContext.NoDeleteMessageIdSet.Add(reply.Id);
        }
Ejemplo n.º 2
0
        protected override async Task _Invoke(MessageContext context)
        {
            var args        = context.GetSequentialArgs(Triggers.Length);
            int deleteDelay = (args.Length > 0 && int.TryParse(args[0], out deleteDelay))
                ? deleteDelay
                : DefaultDeleteDelay;

            var            messageId = context.MessageEvent.Message.Id;
            DiscordMessage reply;

            var channelId    = context.MessageEvent.Channel.Id;
            var wasEphemeral = EphemeralData.ContainsId(channelId);

            if (EphemeralData.Put(channelId, deleteDelay))
            {
                if (wasEphemeral)
                {
                    reply = await context.Reply($"Updated this channel's ephemeral delay, now {deleteDelay} seconds.").ConfigureAwait(false);
                }
                else
                {
                    reply = await context.Reply($"This channel is now ephemeral, delay is {deleteDelay} seconds.").ConfigureAwait(false);
                }
            }
            else
            {
                if (wasEphemeral)
                {
                    reply = await context.Reply(":x: Error: could not update this channel's ephemeral delay.").ConfigureAwait(false);
                }
                else
                {
                    reply = await context.Reply(":x: Error: could not mark this channel as ephemeral.").ConfigureAwait(false);
                }
            }

            EphemeralContext.NoDeleteMessageIdSet.Add(messageId);
            EphemeralContext.NoDeleteMessageIdSet.Add(reply.Id);
        }
        protected override async Task _Invoke(MessageContext context)
        {
            DiscordChannel channel = context.MessageEvent.Channel;
            ulong          id      = channel.Id;

            try
            {
                if (EphemeralData.ContainsId(id))
                {
                    await context.Reply($"This channel is ephemeral; delay is {EphemeralData.Get(id)} seconds.").ConfigureAwait(false);
                }
                else
                {
                    await context.Reply("This channel is not ephemeral.").ConfigureAwait(false);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Ejemplo n.º 4
0
        protected override async Task _Invoke(MessageContext context)
        {
            if (_ephemeralContext.NoDeleteMessageIdSet.Contains(context.MessageEvent.Message.Id))
            {
                _ephemeralContext.NoDeleteMessageIdSet.Remove(context.MessageEvent.Message.Id);
                return;
            }

            var channelId = context.MessageEvent.Channel.Id;

            if (EphemeralData.Get(channelId) == 0)
            {
                await context.MessageEvent.Message.DeleteAsync().ConfigureAwait(false);

                return;
            }

            var deleteTimer = new Timer(EphemeralData.Get(channelId) * 1000);

            deleteTimer.Elapsed  += (sender, args) => context.MessageEvent.Message.DeleteAsync();
            deleteTimer.AutoReset = false;
            deleteTimer.Enabled   = true;
        }
Ejemplo n.º 5
0
 protected override bool IsTriggeredByMessage(MessageContext context)
 {
     return(EphemeralData.ContainsId(context.MessageEvent.Channel.Id));
 }