public async Task Status([Remainder] string input = null) { using (var database = new GuildDB()) { // log execution CommandMethods.LogExecution(logger, "get status", Context); // indicate that the command is being worked on await Context.Channel.TriggerTypingAsync(); GuildTB gtb = statecollection.GetGuildEntry(Context.Guild, database); StringConverter language = statecollection.GetLanguage(Context.Guild, database, gtb); // make sure that the user has the right permissions if (!PermissionHelper.UserHasPermission(Context.User as SocketGuildUser, PermissionHelper.Admin, database)) { await Context.Channel.SendMessageAsync(language.GetString("command.nopermission")); return; } // get all the data from the database ApplicationTB apptb = statecollection.GetApplicationEntry(Context.Guild, database); SocketTextChannel pc = statecollection.GetPublicChannel(Context.Guild, database, gtb); SocketTextChannel nc = statecollection.GetNotificationChannel(Context.Guild, database, gtb); EmbedBuilder eb = new EmbedBuilder() .WithColor(Color.Gold) .WithTitle($":clipboard: Status information for '{gtb.Name}'"); eb.AddField("Language", gtb.Language); eb.AddField("Public channel", (pc != null ? pc.Mention : "Undefined")); eb.AddField("Notification channel", (nc != null ? nc.Mention : "Undefined")); eb.AddField("Application", (apptb != null ? $"ends on: {apptb.Deadline.ToString("dd MMMM a\\t hh:mm tt UTC")}" : "No active application")); await Context.Channel.SendMessageAsync(statecollection.GetLanguage(Context.Guild, database, gtb).GetString("present"), embed : eb.Build()); } }
public async Task StartApplications([Remainder] string input = null) { using (var database = new GuildDB()) { // log command execution CommandMethods.LogExecution(logger, "application start", Context); // indicate that the bot is working on the command await Context.Channel.TriggerTypingAsync(); GuildTB dbentry = statecollection.GetGuildEntry(Context.Guild, database); var language = statecollection.GetLanguage(Context.Guild, database, dbentry); // make sure that the user has the right permissions if (!PermissionHelper.UserHasPermission(Context.User as SocketGuildUser, PermissionHelper.Admin, database)) { await Context.Channel.SendMessageAsync(language.GetString("command.nopermission")); return; } // allow only 1 application per guild if (statecollection.GetApplicationEntry(Context.Guild, database) != null) { await Context.Channel.SendMessageAsync(language.GetString("command.appstart.isactive")); return; } // command must have input if (input == null) { await Context.Channel.SendMessageAsync(language.GetString("command.appstart.empty")); return; } // user must have a timezone TimeZoneInfo usertimezone = DateTimeMethods.UserToTimezone(Context.User); if (usertimezone == null) { await Context.Channel.SendMessageAsync(language.GetString("command.appstart.notimezone")); return; } // given deadline must be in proper format DateTime?localdeadline = DateTimeMethods.StringToDatetime(input); if (!localdeadline.HasValue) { await Context.Channel.SendMessageAsync(language.GetString("command.appstart.error")); return; } DateTime utcdeadline = TimeZoneInfo.ConvertTimeToUtc(localdeadline.Value, usertimezone); // deadline must be in the future if (utcdeadline < DateTime.UtcNow) { await Context.Channel.SendMessageAsync(language.GetString("command.appstart.past")); return; } // creation must succeed IInviteMetadata invite = await statecollection.StartApplication(Context.Guild, database, utcdeadline, dbentry); if (invite == null) { await Context.Channel.SendMessageAsync(language.GetString("command.appstart.error")); return; } // return success to the user await Context.Channel.SendMessageAsync(language.GetString("command.appstart.success", new SentenceContext() .Add("url", invite.Url))); } }