Esempio n. 1
0
        public static async void Kill(DiscordUserMessageContext context)
        {
            await context.Reply("Why??? Why do you do this to meeeeeeeeeeeeeeeeeeeeeeeeeeeee");

            context.Bot.Settings.StartupReplyChannel = context.Channel.Id;
            context.Bot.Settings.SaveConfig();
            Environment.Exit(0);
        }
Esempio n. 2
0
        public static async Task <ICommandResult> Analytics(DiscordUserMessageContext context, bool includeMessageText = false)
        {
            await(await context.Channel.SendMessageAsync("This is going to take a while")).AddReactionAsync(CommandTools.LoadingEmote);

            using (context.Channel.EnterTypingState())
            {
                // Channel Name => User Name => Date => Hour
                List <string> data = new List <string>();
                data.Add($"MessageID\tChannel\tUser\tIsBot\tTimestamp\tUnixTimestamp\tEditedTimestamp\tUnixEditedTimestamp\tMessageLength\tEmbedType\tHasAttachment\tReactionCount{(includeMessageText ? "\tMessage Text" : "")}");
                var channels = await context.Guild.GetTextChannelsAsync();

                foreach (ITextChannel channel in channels)
                {
                    ChannelPermissions permissions = (await context.Guild.GetCurrentUserAsync()).GetPermissions(channel);
                    if (!permissions.ViewChannel || !permissions.ReadMessageHistory)
                    {
                        continue;
                    }

                    var pages = channel.GetMessagesAsync(int.MaxValue);
                    pages.ForEach(
                        page =>
                    {
                        foreach (IMessage message in page)
                        {
                            var timestampLocal = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(message.Timestamp, context.Bot.DefaultTimeZone);
                            DateTimeOffset?editedTimestampLocal = null;
                            if (message.EditedTimestamp != null)
                            {
                                editedTimestampLocal = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(message.EditedTimestamp.Value, context.Bot.DefaultTimeZone);
                            }
                            data.Add($"{message.Id}\t{message.Channel.Name}\t{message.Author}\t{message.Author.IsBot}\t{timestampLocal.DateTime:G}\t{timestampLocal.ToUnixTimeSeconds()}\t{editedTimestampLocal?.ToString("G") ?? ""}\t{editedTimestampLocal?.ToUnixTimeSeconds().ToString() ?? ""}\t{new System.Globalization.StringInfo(message.Content).LengthInTextElements}\t{message.Embeds.FirstOrDefault()?.Type.ToString() ?? ""}\t{message.Attachments.Count > 0}\t{(message as IUserMessage)?.Reactions.Count ?? 0}{(includeMessageText ? $"\t{message.Content.Replace("\n", "␊").Replace("\r", "")}" : "")}");
                        }
                    });
                }

                File.WriteAllLines(Config.BasePath + $"analytics-{context.Guild.Id}.txt", data);

                if (!includeMessageText)
                {
                    using (var stream = File.OpenRead(Config.BasePath + $"analytics-{context.Guild.Id}.txt"))
                    {
                        await context.Channel.SendFileAsync(stream, $"analytics-{context.Guild.Id}-{DateTimeOffset.Now.ToUnixTimeSeconds()}.txt");
                    }
                }
                else
                {
                    await context.Reply($"Finished creating analytics file. Saved as `analytics-{context.Guild.Id}.txt` ({Math.Round(new FileInfo(Config.BasePath + $"analytics-{context.Guild.Id}.txt").Length / 1048576d, 2)} MB)");
                }
            }
            return(new SuccessResult());
        }