示例#1
0
        public async Task SendFeedback(CommandContext ctx, [RemainingText] string message)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(message))
                {
                    await ctx.ReplyAsync("You may use this command to send a message to the bot's developer.");

                    return;
                }

                File.AppendAllText(Files.FeedbackLog, $"[{ctx.User.DebugName()}] {message}\n\n");

                foreach (var owner in ShardedClient.CurrentApplication.Owners)
                {
                    string content = $"```diff\n+Feedback received: {ctx.User.DebugName()}```\n{message}".Truncate(2000);
                    await ShardedClient.DmUserAsync(owner.Id, content);

                    await ctx.ReplyAsync($"{CustomEmoji.Check} Message sent. Thank you!");

                    return;
                }
                throw new InvalidOperationException("Couldn't find owner member");
            }
            catch (Exception e)
            {
                Log.Exception($"Sending feedback from {ctx.User.DebugName()} at {ctx.Channel.DebugName()}", e);
                await ctx.ReplyAsync("Oops, I didn't catch that, please try again. " +
                                     "If this keeps happening join the support server to let my owner know.");
            }
        }
示例#2
0
        public async Task ReplyFeedback(CommandContext ctx, ulong userId, [RemainingText] string message)
        {
            try
            {
                string pre = "```diff\n+The following message was sent to you by this bot's owner." +
                             "\n-To reply to this message, use the 'feedback' command.```\n";

                await ShardedClient.DmUserAsync(userId, pre + message);

                await ctx.AutoReactAsync();
            }
            catch (Exception e)
            {
                Log.Debug($"{e.Message}");
                await ctx.AutoReactAsync(false);

                await ctx.RespondAsync($"```{e.Message}```");
            }
        }
        private async Task CheckDuplicateModuleNames()
        {
            var modnames  = CService.Modules.Select(m => m.Name).ToList();
            var multiples = modnames.Where(name => modnames.Count(str => str.Equals(name, StringComparison.OrdinalIgnoreCase)) > 1);

            if (multiples.Any())
            {
                var error = $@"Multiple modules with the same Name have been registered, SimplePermissions cannot function.
    Duplicate names: {String.Join(", ", multiples.Distinct())}.";
                await Log(LogSeverity.Error, error);

                throw new Exception(error);
            }

            if (SocketClient != null)
            {
                SocketClient.Ready -= CheckDuplicateModuleNames;
            }

            if (ShardedClient != null)
            {
                ShardedClient.GetShard(0).Ready -= CheckDuplicateModuleNames;
            }
        }
示例#4
0
        public async Task SetStatus(CommandContext ctx, UserStatus status)
        {
            await ShardedClient.UpdateStatusAsync(userStatus : status);

            await ctx.AutoReactAsync();
        }
示例#5
0
        public async Task SetStatus(CommandContext ctx, ActivityType type, [RemainingText] string status)
        {
            await ShardedClient.UpdateStatusAsync(new DiscordActivity(status, type));

            await ctx.AutoReactAsync();
        }
示例#6
0
        public async Task BirthdayAsync()
        {
            try
            {
                var notifiableList = await BirthdayService.GetNotifiableList();

                foreach (var guildSetup in notifiableList)
                {
                    var guild   = ShardedClient.GetGuild(guildSetup.Item1.GuildId);
                    var channel = guild?.GetTextChannel(guildSetup.Item1.BirthdayChannelId);
                    if (channel == null)
                    {
                        continue;
                    }

                    bool?manageRoles = guild.GetUser(ShardedClient.CurrentUser.Id)?.GuildPermissions.ManageRoles;

                    SocketRole birthdayRole = null;
                    if (guildSetup.Item1.BirthdayRole != 0)
                    {
                        birthdayRole = guild.GetRole(guildSetup.Item1.BirthdayRole);
                    }

                    if (birthdayRole == null)
                    {
                        continue;
                    }

                    var userList = new List <string>();
                    foreach (var person in guildSetup.Item2)
                    {
                        string mentionContent = "";
                        int    age            = person.Age();
                        var    user           = guild.GetUser(person.UserId);
                        if (user.Roles.Contains(birthdayRole))
                        {
                            continue;
                        }

                        mentionContent = age > 0 ? $"{user.Mention} | Age: {age}" : user.Mention;

                        userList.Add(mentionContent);

                        if (manageRoles == true)
                        {
                            try
                            {
                                await user.AddRoleAsync(birthdayRole);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.ToString());
                            }
                        }
                    }

                    if (userList.Any(x => !string.IsNullOrEmpty(x)))
                    {
                        await channel.SendMessageAsync("Today's Current birthdays are: \n" + string.Join("\n", userList.Where(x => !string.IsNullOrEmpty(x))));
                    }

                    if (manageRoles == true)
                    {
                        foreach (var member in birthdayRole.Members)
                        {
                            if (guildSetup.Item2.All(x => x.UserId != member.Id))
                            {
                                try
                                {
                                    await member.RemoveRoleAsync(birthdayRole);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e.ToString());
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }