private async Task ServerSetup(ParseResult result, IMessageCreatedEvent context)
        {
            if (context.Guild != null)
            {
                await context.Respond("Server already active");

                return;
            }

            if (context is DiscordMessageCreatedEvent dmce)
            {
                var message = dmce.@event;

                DiscordGuild discord_guild = message.Guild;


                var member = await message.Guild.GetMemberAsync(message.Message.Author.Id);

                var permissions = member.PermissionsIn(message.Message.Channel);
                if (permissions.HasPermission(Permissions.Administrator) || member.Id.ToString() == config.Value.Owner)
                {
                    Guild?guild = (from g in context.Db.Guilds
                                   where g.GuildID == discord_guild.Id
                                   select g).FirstOrDefault();

                    if (guild == null)
                    {
                        logger.Information($"Registering guild: {discord_guild.Id}");

                        context.Db.Add(new Guild(discord_guild.Name, discord_guild.Id.ToString()));
                        context.Db.SaveChanges();

                        var embed = new DSharpPlus.Entities.DiscordEmbedBuilder()
                        {
                            Description = "Server setup complete!"
                        };

                        await message.Message.RespondAsync(embed : embed.Build());
                    }
                }
                else
                {
                    await message.Message.RespondAsync("You do not have the permission");
                }
            }
        }
Example #2
0
        public async Task EndGame(CommandContext ctx)
        {
            string endingplayer = nicknamelist.Where(m => m.Item1 == ctx.User).First().ToString(); // Finds each dm channel by discorduser

            if (ctx.User != nicknamelist[currentplayer].Item1)
            {
                var embedwarn = new DiscordEmbedBuilder(GeneralMessageEmbed)
                {
                    Color       = new DiscordColor("#FFFF00"),
                    Title       = "Právě nejsi na řadě!",
                    Description = "Jak můžeš vědět, že se má příběh ukončit?! Pokud se jedná o krizovku, kdy drzý drzoun utekl od svého zažízení, napiš pro potvrzení zprávu **reallyend**.",
                };
                await ctx.Message.RespondAsync(embed : embedwarn.Build());

                var interactivity = ctx.Client.GetInteractivityModule();
                var msg           = await interactivity.WaitForMessageAsync(xm => xm.Author.Id == ctx.User.Id && xm.Content.ToLower() == "reallyend", TimeSpan.FromMinutes(1));

                if (msg != null)
                {
                    await storychannel.SendMessageAsync(embed : StoryEmbed.Build());

                    // Send shit to website etc
                    await PostStory(ctx);

                    foreach (var player in nicknamelist)
                    {
                        var playerDMchannel = DMChannels.Where(m => m.Recipients.First() == player.Item1).First(); // Finds each dm channel by discorduser
                        var nick            = player.Item2;                                                        // users nickname
                        var embedplayer     = new DiscordEmbedBuilder(GeneralMessageEmbed)
                        {
                            Title       = $"Hej {nick}! Hra skončila!",
                            Description = $"Věř tomu nebo ne, hráč {endingplayer} vše skončil. Příběh nalezneš na https://nase.example.com/stories/cs/blog/{webStoryPageName}",
                        };
                        // Different messages for starting player and rest of the squad.
                        await playerDMchannel.SendMessageAsync(embed : embedplayer.Build());
                    }
                    ctx.Client.DebugLogger.LogMessage(level: LogLevel.Info, application: "prdelbot-story", message: $"[{ctx.Message.Author.Username}] forced end of story.", timestamp: DateTime.Now);
                }
            }
            else
            {
                var webStorySentence      = ctx.Message.Content.Substring(5); // Gets current sentence
                var currentPlayerNickname = nicknamelist[currentplayer].Item2;
                webStoryContent.Add(new Tuple <string, string>($"[{nicknamelist[currentplayer].Item1.Username}]{currentPlayerNickname}", webStorySentence));
                StoryEmbed.AddField($"{$"{currentPlayerNickname} "}", ctx.Message.Content.Substring(5));
                await storychannel.SendMessageAsync(embed : StoryEmbed.Build());

                // Send shit to website etc
                await PostStory(ctx);

                foreach (var player in nicknamelist)
                {
                    var playerDMchannel = DMChannels.Where(m => m.Recipients.First() == player.Item1).First(); // Finds each dm channel by discorduser
                    var nick            = player.Item2;                                                        // users nickname
                    var embedplayer     = new DiscordEmbedBuilder(GeneralMessageEmbed)
                    {
                        Title       = $"Hej {nick}! Hra skončila!",
                        Description = $"Věř tomu nebo ne, hráč {endingplayer} vše skončil. Příběh nalezneš na https://nase.example.com/stories/cs/blog/{webStoryPageName}",
                    };
                    // Different messages for starting player and rest of the squad.
                    await playerDMchannel.SendMessageAsync(embed : embedplayer.Build());
                }
                ctx.Client.DebugLogger.LogMessage(level: LogLevel.Info, application: "prdelbot-story", message: $"[{nicknamelist[currentplayer].Item1.Username}]{currentPlayerNickname} - {webStorySentence}", timestamp: DateTime.Now);
            }


            // Dispose all variables
            round         = 1;
            currentplayer = 0;
            firstsentence = true;
            webStoryTitle = null;
            webStoryDate  = null;
            webStoryContent.Clear();
            StoryEmbed.ClearFields();
            await ctx.Client.UpdateStatusAsync(new DiscordGame("with masself"));
        }