示例#1
0
        public async Task Ping([Remainder] string input = null)
        {
            using (var database = new GuildDB())
            {
                // log command execution
                CommandMethods.LogExecution(logger, "ping", Context);

                // indicate that the bot is working on the command
                await Context.Channel.TriggerTypingAsync();

                string response;
                if (Context.Guild != null)
                {
                    var language = statecollection.GetLanguage(Context.Guild, database);

                    // make sure that the user has the right permissions
                    if (!PermissionHelper.UserHasPermission(Context.User as SocketGuildUser, PermissionHelper.Public, database))
                    {
                        await Context.Channel.SendMessageAsync(language.GetString("command.nopermission"));

                        return;
                    }

                    response = statecollection.GetLanguage(Context.Guild, database).GetString("command.ping");
                }
                else
                {
                    response = "pong";
                }
                await Context.Channel.SendMessageAsync(response);
            }
        }
示例#2
0
        public async Task unset_public([Remainder] string input = null)
        {
            using (var database = new GuildDB())
            {
                // log command execution
                CommandMethods.LogExecution(logger, "unset public", Context);

                // indicate that the bot is working on the command
                await Context.Channel.TriggerTypingAsync();

                // apply change and report to user
                GuildTB gtb      = statecollection.GetGuildEntry(Context.Guild, database);
                var     language = statecollection.GetLanguage(Context.Guild, database, gtb);

                // make sure that the user has the right permissions
                if (!PermissionHelper.UserHasPermission(Context.User as SocketGuildUser, PermissionHelper.Owner, database))
                {
                    await Context.Channel.SendMessageAsync(language.GetString("command.nopermission"));

                    return;
                }

                gtb.Public = null;
                statecollection.SetGuildEntry(gtb, database);
                await Context.Channel.SendMessageAsync(language.GetString("command.unset.public"));
            }
        }
示例#3
0
        public async Task Kill()
        {
            using (var database = new GuildDB())
            {
                // log command execution
                CommandMethods.LogExecution(logger, "kill", Context);

                if (Context.Guild != null)
                {
                    StringConverter language = statecollection.GetLanguage(Context.Guild, database);
                    await Context.Channel.SendMessageAsync(language.GetString("command.exit"));
                }
                else
                {
                    await Context.Channel.SendMessageAsync("Shutting down now...");
                }

                bot.Stop();
            }
        }
示例#4
0
        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());
            }
        }
示例#5
0
        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)));
            }
        }