Ejemplo n.º 1
0
        [Command("queryd", RunMode = RunMode.Async)] // better name xD
        public async Task SqlD([Remainder] string commandSql)
        {
            var userId = Context.Message.Author.Id;

            if (AllowedToRun(BotPermissionType.EnableType2Commands))
            {
                return;
            }

            if (ForbiddenQuery(commandSql, Context.Message.Author.Id))
            {
                return;
            }

            if (ActiveSQLCommands.ContainsKey(userId) && ActiveSQLCommands[userId].AddSeconds(15) > DateTime.Now)
            {
                await Context.Channel.SendMessageAsync("Are you in such a hurry, that you cant wait out the last query you send out?", false);

                return;
            }

            try
            {
                if (ActiveSQLCommands.ContainsKey(userId))
                {
                    ActiveSQLCommands[userId] = DateTime.Now;
                }
                else
                {
                    ActiveSQLCommands.Add(userId, DateTime.Now);
                }

                var queryResult = await SQLHelper.GetQueryResults(Context, commandSql, true, 50);

                string additionalString = $"Total row(s) affected: {queryResult.TotalResults.ToString("N0")} QueryTime: {queryResult.Time.ToString("N0")}ms";


                var drawTable = new DrawTable(queryResult.Header, queryResult.Data, additionalString);

                var stream = await drawTable.GetImage();

                if (stream == null)
                {
                    return;// todo some message
                }
                await Context.Channel.SendFileAsync(stream, "graph.png", "", false, null, null, false, null, new Discord.MessageReference(Context.Message.Id));

                stream.Dispose();

                // release the user again as the query finished
                ActiveSQLCommands[userId] = DateTime.MinValue;
            }
            catch (Exception ex)
            {
                await Context.Channel.SendMessageAsync("Is this all you got <:kekw:768912035928735775> " + ex.ToString(), false);
            }
        }
Ejemplo n.º 2
0
            public async Task GetLockInfo()
            {
                ulong guildId = Program.BaseGuild;

#if DEBUG
                guildId = 774286694794919986;
#endif

                var guild = Program.Client.GetGuild(guildId);


                var channels = guild.Channels;

                var sortedDict = from entry in Program.ChannelPositions orderby entry.Value ascending select entry;

                List <string> header = new List <string>()
                {
                    "Order",
                    "Channel Name",
                    "Id"
                };


                List <List <string> > data = new List <List <string> >();

                foreach (var item in sortedDict)
                {
                    var channel = channels.SingleOrDefault(i => i.Id == item.Key);
                    if (channel == null)
                    {
                        continue;
                    }

                    var currentRecord = new List <string>();

                    currentRecord.Add(item.Value.ToString());
                    currentRecord.Add(Regex.Replace(channel.Name, @"[^\u0000-\u007F]+", string.Empty));
                    currentRecord.Add(item.Key.ToString());


                    data.Add(currentRecord);
                }

                var drawTable = new DrawTable(header, data, "");

                var stream = await drawTable.GetImage();

                if (stream == null)
                {
                    return;// todo some message
                }
                await Context.Channel.SendFileAsync(stream, "graph.png", "", false, null, null, false, null, new Discord.MessageReference(Context.Message.Id));

                stream.Dispose();
            }
Ejemplo n.º 3
0
            public async Task GetChannelInfoAsync(bool all = false)
            {
                var guildUser = Context.Message.Author as SocketGuildUser;
                var author    = Context.Message.Author;

                if (!(author.Id == ETHDINFKBot.Program.Owner || guildUser.GuildPermissions.ManageChannels))
                {
                    Context.Channel.SendMessageAsync("You aren't allowed to run this command", false);
                    return;
                }

                if (Context.Message.Channel is SocketGuildChannel guildChannel)
                {
                    if (!all)
                    {
                        var channelInfo = DatabaseManager.Instance().GetChannelSetting(guildChannel.Id);
                        var botSettings = DatabaseManager.Instance().GetBotSettings();

                        if (channelInfo == null)
                        {
                            Context.Channel.SendMessageAsync("channelInfo is null bad admin", false);
                            return;
                        }

                        EmbedBuilder builder = new EmbedBuilder();
                        builder.WithTitle($"Channel Info for {guildChannel.Name}");
                        builder.WithDescription($"Global Channel position lock active: {botSettings.ChannelOrderLocked} for " +
                                                $"{(botSettings.ChannelOrderLocked ? Program.ChannelPositions.Count : -1)} channels");
                        builder.WithColor(255, 0, 0);
                        builder.WithThumbnailUrl(Program.Client.CurrentUser.GetAvatarUrl());

                        builder.WithCurrentTimestamp();

                        builder.AddField("Permission flag", channelInfo.ChannelPermissionFlags);

                        foreach (BotPermissionType flag in Enum.GetValues(typeof(BotPermissionType)))
                        {
                            var hasFlag = ((BotPermissionType)channelInfo.ChannelPermissionFlags).HasFlag(flag);
                            builder.AddField(flag.ToString() + $" ({(int)flag})", $"```diff\r\n{(hasFlag ? "+ YES" : "- NO")}```", true);
                        }


                        Context.Channel.SendMessageAsync("", false, builder.Build());
                    }
                    else
                    {
                        var botChannelSettings = DatabaseManager.Instance().GetAllChannelSettings();

                        List <string> header = new List <string>()
                        {
                            "Channel Id",
                            "Channel Name",
                            "Permission value",
                            "Permission string",
                            "Preload old",
                            "Preload new",
                            "Reached oldest"
                        };


                        List <List <string> > data = new List <List <string> >();


                        foreach (var channelSetting in botChannelSettings)
                        {
                            List <string> channelInfoRow = new List <string>();

                            var discordChannel = DatabaseManager.Instance().GetDiscordChannel(channelSetting.DiscordChannelId);

                            if (discordChannel.DiscordServerId != guildChannel.Guild.Id)
                            {
                                break; // dont show other server
                            }
                            channelInfoRow.Add(discordChannel.DiscordChannelId.ToString());
                            channelInfoRow.Add(discordChannel.ChannelName);
                            channelInfoRow.Add(channelSetting.ChannelPermissionFlags.ToString());
                            List <string> permissionFlagNames = new List <string>();
                            foreach (BotPermissionType flag in Enum.GetValues(typeof(BotPermissionType)))
                            {
                                var hasFlag = ((BotPermissionType)(channelSetting.ChannelPermissionFlags)).HasFlag(flag);

                                if (hasFlag)
                                {
                                    permissionFlagNames.Add($"{flag} ({(int)flag})");
                                }
                            }

                            channelInfoRow.Add(string.Join(", " + Environment.NewLine, permissionFlagNames));
                            channelInfoRow.Add(channelSetting.OldestPostTimePreloaded?.ToString());
                            channelInfoRow.Add(channelSetting.NewestPostTimePreloaded?.ToString());
                            channelInfoRow.Add(channelSetting.ReachedOldestPreload.ToString());
                            data.Add(channelInfoRow);
                        }

                        var drawTable = new DrawTable(header, data, "");

                        var stream = await drawTable.GetImage();

                        if (stream == null)
                        {
                            return;// todo some message
                        }
                        await Context.Channel.SendFileAsync(stream, "graph.png", "", false, null, null, false, null, new Discord.MessageReference(Context.Message.Id));

                        stream.Dispose();
                    }
                }
            }