示例#1
0
        public async Task ProcessCommand(MessageCreateEventArgs messageEvent)
        {
            this.messageEvent = messageEvent;
            DiscordMessage message = messageEvent.Message;

            if (message.Content == "streambot!ping")
            {
                await Ping(message);
            }
            else if (message.Content == "streambot!login")
            {
                await RequestLogin(message);
            }
            else if (message.Content == "streambot!up")
            {
                if (CheckRole(message))
                {
                    Client.StreamUp = true;
                    await message.RespondAsync(embed : PresetEmbeds.SuccessEmbed("Stream marked as up.", message).Build());

                    await Client.MessageHandler.StreamUp();
                }
                else
                {
                    await message.RespondAsync(embed : PresetEmbeds.ErrorEmbed("Insufficient permissions.", message).Build());
                }
            }
            else if (message.Content == "streambot!down")
            {
                if (CheckRole(message))
                {
                    Client.StreamUp = false;
                    await message.RespondAsync(embed : PresetEmbeds.SuccessEmbed("Stream marked as down.", message).Build());
                }
                else
                {
                    await message.RespondAsync(embed : PresetEmbeds.ErrorEmbed("Insufficient permissions.", message).Build());
                }
            }
            else if (message.Content == "streambot!status")
            {
                await message.RespondAsync(embed : PresetEmbeds.InfoEmbed($"Stream running: {Client.StreamUp}", message).Build());
            }
            else if (message.Content.StartsWith("streambot!"))
            {
                await message.RespondAsync(embed : PresetEmbeds.ErrorEmbed("Use `streambot!login` in a DM to request a login link.", message).Build());
            }
        }
示例#2
0
        private async Task RequestLogin(DiscordMessage message)
        {
            if (!message.Channel.IsPrivate)
            {
                await message.RespondAsync(embed : PresetEmbeds.ErrorEmbed("This command must be run in a DM.", message).Build());
            }
            else
            {
                DiscordGuild streamGuild = messageEvent.Guild.GetChannel(StreamChannel).Guild;
                if (await streamGuild.GetMemberAsync(message.Author.Id) == null)
                {
                    await message.RespondAsync(embed : PresetEmbeds.ErrorEmbed($"We can't find you in our guild. are you part of {streamGuild.Name}?", message).Build());

                    return;
                }

                string signedId    = Hmac.SignMessage(message.Author.Id.ToString(), TokenKey);
                string encryptedId = StringCipher.Encrypt(signedId, TokenPassword);

                await message.RespondAsync(embed : PresetEmbeds.SuccessEmbed($"[Click here to login.]({ApiUrl}BotLogin?token={encryptedId})\n\n" +
                                                                             $"This link expires in 30 seconds.", message).Build());
            }
        }