Example #1
0
 public async Task ApplySetting(string name, [Remainder] string value)
 {
     if (_settings.Has(name))
     {
         _settings.Set(name, value);
         await ReplyAsync("I updated the setting for you!");
     }
     else
     {
         _settings.Add(name, value);
         await ReplyAsync("I added the setting for you!");
     }
 }
Example #2
0
        public async Task ArchiveChannel(ISocketMessageChannel channel, [Remainder] string title)
        {
            var messages = await channel.GetMessagesAsync().Flatten();

            using (ChannelArchive archive = new ChannelArchive(title))
            {
                string voteEmote = _settings.Has("brackeys-emote") ? _settings.Get("brackeys-emote").Split(':').First() : string.Empty;

                foreach (IMessage msg in messages)
                {
                    ArchiveMessage             archiveMessage = new ArchiveEventSubmission(msg, voteEmote);
                    IEnumerable <ArchiveImage> archiveImages  = archiveMessage.GetMessageImages();

                    archive.AddMessage(archiveMessage);
                    foreach (ArchiveImage image in archiveImages)
                    {
                        archive.AddImage(image);
                    }
                }

                archive.CloseArchive();
                string zippedArchive = archive.ZipArchive();

                WeTransferClient wt = new WeTransferClient(BrackeysBot.Configuration["wetransfer-api-key"]);
                // Make sure we are authorized
                await wt.Authorize();

                var fileInfo = new System.IO.FileInfo(zippedArchive);
                // Create Partial File Information so WeTransfer knows how many files
                // you're going to upload, the names of those files and their sizes
                PartialFileInfo[] partialFileInfos = new PartialFileInfo[]
                {
                    new PartialFileInfo
                    {
                        Name = fileInfo.Name,
                        Path = fileInfo.FullName,
                        Size = (int)fileInfo.Length
                    }
                };

                // Create a File Transfer which informs WeTransfer that you're about to upload files
                // The second parameter is the transfer message which will show on the download page
                FileTransferResponse response = await wt.CreateTransfer(partialFileInfos, $"Download the archived channel #{channel.Name}!");

                // Now you can upload the files!
                // The first parameter is the transfer's ID
                await wt.Upload(response.ID, response.Files);

                // Now you need to tell WeTransfer that your files have been uploaded
                FileUploadResult result = await wt.FinalizeUpload(response.ID, response.Files);

                // FileUploadResult contains the url to the download page and the date of the expiry

                StringBuilder reply = new StringBuilder()
                                      .AppendLine($"I archived the channel <#{channel.Id}> for you{(title == channel.Name ? "!" : $", under the name **{title}**!")}")
Example #3
0
        public async Task InitializeGiveaway([Remainder] string message)
        {
            // Delete the invokation message
            await Context.Message.DeleteAsync();

            // Reply with the specified message
            var botMessage = await ReplyAsync(message);

            // Find the giveaway emote and add it as a reaction
            var emote = _settings.Get(GIVEAWAY_EMOTE_IDENTIFIER);
            await botMessage.AddReactionAsync(new Emoji(emote));

            // Save the giveaway message id
            string identifier = $"{botMessage.Channel.Id}/{botMessage.Id.ToString()}";

            if (!_settings.Has(GIVEAWAY_MESSAGE_IDENTIFIER))
            {
                _settings.Add(GIVEAWAY_MESSAGE_IDENTIFIER, identifier);
            }
            else
            {
                _settings.Set(GIVEAWAY_MESSAGE_IDENTIFIER, identifier);
            }
        }
Example #4
0
        public async Task ApplySetting(string name, [Remainder] string value)
        {
            (Context.User as IGuildUser).EnsureStaff();

            if (_settings.Has(name))
            {
                _settings.Set(name, value);
            }
            else
            {
                _settings.Add(name, value);
            }

            await ReplyAsync("Setting has been applied.");
        }
Example #5
0
        public async Task JamTimeLeftCommand()
        {
            if (!_settings.Has("jamevents"))
            {
                await ReplyAsync("No jam event dates have been set.");

                return;
            }

            // Ordered by:
            // [0]: Jam Start
            // [1]: Jam End
            // [2]: Voting End
            string jamEventDates = _settings.Get("jamevents");
            var    dateStrings   = jamEventDates.Split(',').Select(d => d.Trim());

            DateTime[] dates  = dateStrings.Select(date => DateTime.ParseExact(date, DATEFORMAT, null, System.Globalization.DateTimeStyles.None)).ToArray();
            DateTime   utcNow = DateTime.UtcNow;

            if (dates.Length != 3)
            {
                await ReplyAsync("Invalid jam date configuration. Please check the settings.");
            }

            if (dates[0] > utcNow)
            {
                string until = ConvertTimespanToString(dates[0] - utcNow);
                await ReplyAsync($"The jam will start in { until }.");
            }
            else if (dates[1] > utcNow)
            {
                string remaining = ConvertTimespanToString(dates[1] - utcNow);
                await ReplyAsync($"The jam has started! There are { remaining } remaining");
            }
            else if (dates[2] > utcNow)
            {
                string remaining = ConvertTimespanToString(dates[2] - utcNow);
                await ReplyAsync($"The jam has ended. There are { remaining } of the voting phase remaining.");
            }
            else
            {
                await ReplyAsync("The voting phase has ended! There are no jam events scheduled at the moment.");
            }
        }