Example #1
0
        public async Task Snoop([Remainder] string server)
        {
            var guild = _client.Guilds.ToList()
                        .FirstOrDefault(x => string.Equals(x.Name, server, StringComparison.CurrentCultureIgnoreCase));

            if (guild == null)
            {
                await ReplyAsync("", false, EmbedHelper.CreateEmbed("Snoop", "Guild not found", Color.Orange));
            }
            else
            {
                var embedBuilder = new EmbedBuilder {
                    Title = $"**Snoop - {server}**"
                };
                embedBuilder.Description += "**Members - " + guild.MemberCount + "**" + Environment.NewLine;
                embedBuilder.Description += string.Join(", ", guild.Users.ToList().Where(x => !x.IsBot));
                embedBuilder.Description += Environment.NewLine;
                embedBuilder.Description += "**Bots**" + Environment.NewLine;
                embedBuilder.Description += string.Join(", ", guild.Users.ToList().Where(x => x.IsBot));
                embedBuilder.Description += Environment.NewLine;
                embedBuilder.Description += "**Roles**" + Environment.NewLine;
                embedBuilder.Description += string.Join(", ", guild.Roles) + Environment.NewLine;
                embedBuilder.Description += "**Channels**" + Environment.NewLine;
                embedBuilder.Description += string.Join(", ", guild.TextChannels) + Environment.NewLine +
                                            Environment.NewLine;
                await ReplyAsync("", false, embedBuilder);
            }
        }
Example #2
0
        private async Task HandleCommandAsync(SocketMessage messageParam)
        {
            // Don't process the command if it was a System Message
            var message = messageParam as SocketUserMessage;

            if (message == null)
            {
                return;
            }
            // Create a number to track where the prefix ends and the command begins
            var argPos = 0;

            // Determine if the message is a command, based on if it starts with '!' or a mention prefix
            if (!(message.HasCharPrefix('!', ref argPos) ||
                  message.HasMentionPrefix(_client.CurrentUser, ref argPos)))
            {
                return;
            }
            // Create a Command Context
            var context = new SocketCommandContext(_client, message);
            // Execute the command. (result does not indicate a return value,
            // rather an object stating if the command executed successfully)
            var result = await _commands.ExecuteAsync(context, argPos, _services);

            _botStats.CommandsCount++;
            if (!result.IsSuccess)
            {
                await context.Channel.SendMessageAsync("", false,
                                                       EmbedHelper.CreateEmbed(result.ErrorReason, Color.Orange));
            }
        }
Example #3
0
 public async Task ListChannels()
 {
     await ReplyAsync("", false,
                      EmbedHelper.CreateEmbed(
                          Context.Guild.TextChannels.Aggregate("", (x, y) => x + y.Mention + Environment.NewLine),
                          Color.Gold));
 }
Example #4
0
        public async Task AddGiveMeRole([Remainder][Summary("rolename")] string roleName)
        {
            var server = Context.Guild.Id;

            roleName = roleName.Trim(' ');
            if (roleName.Contains("@"))
            {
                if (Context.Guild.Roles.Where(x => x.Mention == roleName).ToList().Count != 0)
                {
                    var name = Context.Guild.Roles.First(x => x.Mention == roleName).Name;
                    _db.AddGiveableRole(server, name);
                    await ReplyAsync("", false, EmbedHelper.CreateEmbed("Add !giveme Role",
                                                                        "Role added successfully.", Color.Green));
                }
                else
                {
                    await ReplyAsync("", false, EmbedHelper.CreateEmbed("Add !giveme Role",
                                                                        "Role not found.", Color.Orange));
                }
            }
            else
            {
                if (Context.Guild.Roles.Where(x => x.Name == roleName).ToList().Count != 0)
                {
                    _db.AddGiveableRole(server, roleName);
                    await ReplyAsync("", false, EmbedHelper.CreateEmbed("Add !giveme Role",
                                                                        "Role added successfully.", Color.Green));
                }
                else
                {
                    await ReplyAsync("", false, EmbedHelper.CreateEmbed("Add !giveme Role",
                                                                        "Role not found.", Color.Orange));
                }
            }
        }
Example #5
0
        public async Task PurgeAsync([Summary("Messages to purge")] uint amount)
        {
            var messages = await Context.Channel.GetMessagesAsync((int)amount + 1).Flatten();

            await Context.Channel.DeleteMessagesAsync(messages);

            const int delay = 3000;

            var m = await ReplyAsync("", false, EmbedHelper.CreateEmbed(
                                         $"Purge completed. _This message will be deleted in {delay / 1000} seconds._", Color.Gold));

            await Task.Delay(delay);

            await m.DeleteAsync();
        }
Example #6
0
 public async Task ListServers()
 {
     //var db = new DataAccess();
     //var serverConfigs = db.GetServerConfigs();
     //var replyList = (from serverConfigModel in serverConfigs
     //    let socketTextChannel = _client.GetChannel(serverConfigModel.AnnouncementId) as SocketTextChannel
     //    where socketTextChannel != null
     //    select
     //    $"Server: {_client.GetGuild(serverConfigModel.ServerId).Name} ({serverConfigModel.ServerId}){Environment.NewLine}Channel: {socketTextChannel.Name} ({serverConfigModel.AnnouncementId})"
     //).ToList();
     await ReplyAsync("", false,
                      EmbedHelper.CreateEmbed(
                          string.Join(Environment.NewLine + Environment.NewLine,
                                      _client.Guilds.ToList().ConvertAll(x => x.Name)), Color.Gold));
 }
Example #7
0
        public async Task GiveRoleListAsync()
        {
            var list = _db.GetGiveableRoles(Context.Guild.Id);

            if (list.Count != 0)
            {
                await ReplyAsync("", false,
                                 EmbedHelper.CreateEmbed("Giveable Roles", string.Join(", ", _db.GetGiveableRoles(Context.Guild.Id)),
                                                         Color.Gold));
            }
            else
            {
                await ReplyAsync("", false, EmbedHelper.CreateEmbed("No giveable roles...", Color.Orange));
            }
        }
Example #8
0
        public async Task SetAnnouncementChannel([Summary("channel")] string channel)
        {
            var channelTextChannel = Context.Guild.TextChannels.First(x => x.Mention == channel);

            if (channelTextChannel != null)
            {
                _db.SetAnnouncementChannel(channelTextChannel.Id, Context.Guild.Id);
                await ReplyAsync("", false, EmbedHelper.CreateEmbed("Set Announcement Channel",
                                                                    "Channel set.", Color.Green));
            }
            else
            {
                await ReplyAsync("", false, EmbedHelper.CreateEmbed("Set Announcement Channel",
                                                                    "Channel not found.", Color.Orange));
            }
        }
Example #9
0
        private async Task _client_JoinedGuild(SocketGuild arg)
        {
            var channel = arg.DefaultChannel;

            if (channel != null)
            {
                await channel.SendMessageAsync("", false, EmbedHelper.CreateEmbed(
                                                   "Thank you for using HonaBot! Please PM `Hona#0856` with suggestions or bugs.\r\nPlease configure the bots announcement channel with `!announcechannel <#channel>`", Color.Gold));
            }
            else
            {
                await arg.Owner.SendMessageAsync(
                    "Thank you for using HonaBot! Please PM `Hona#0856` with suggestions or bugs.");

                await arg.Owner.SendMessageAsync(
                    "Please configure the bots announcement channel with `!announcechannel <#channel>`");
            }
        }
Example #10
0
 public async Task AdminHelp()
 {
     await ReplyAsync("", false, EmbedHelper.CreateEmbed("Admin Help",
                                                         AdminHelpString, Color.Gold));
 }
Example #11
0
        public async Task GiveRoleAsync(string userMention, [Remainder][Summary("Role")] string rolename)
        {
            var success = false;

            rolename    = rolename.Trim(' ');
            userMention = userMention.TrimStart('<', '@').TrimEnd('>');

            var user          = Context.Guild.Users.FirstOrDefault(x => x.Id.ToString() == userMention);
            var giveable      = _db.GetGiveableRoles(Context.Guild.Id);
            var upperGiveable = giveable.ConvertAll(x => x.ToUpper());

            if (upperGiveable.Contains(rolename.ToUpper()))
            {
                var role = Context.Guild.Roles.FirstOrDefault(x => string.Equals(x.Name, rolename,
                                                                                 StringComparison.CurrentCultureIgnoreCase));
                if (user == null)
                {
                    await ReplyAsync("", false,
                                     EmbedHelper.CreateEmbed("Could not give role", "User not found", Color.Orange));

                    return;
                }
                await((IGuildUser)user).AddRoleAsync(role);
                if (role != null)
                {
                    await ReplyAsync("", false,
                                     EmbedHelper.CreateEmbed("Givethem", $"Successfully added {user.Mention} to **{role.Name}**",
                                                             Color.Green));
                }
                else
                {
                    await ReplyAsync("", false, EmbedHelper.CreateEmbed("Could not give role", "Role is null", Color.Orange));
                }
                success = true;
            }
            if (!success)
            {
                rolename = rolename.TrimStart('<', '@', '&').TrimEnd('>');

                var entries = Context.Guild.Roles.ToList().ConvertAll(x => x.Id.ToString());
                if (entries.Contains(rolename))
                {
                    var role = Context.Guild.Roles.FirstOrDefault(x => string.Equals(x.Id.ToString(), rolename,
                                                                                     StringComparison.CurrentCultureIgnoreCase));
                    if (user == null)
                    {
                        await ReplyAsync("", false,
                                         EmbedHelper.CreateEmbed("Could not give role", "User not found", Color.Orange));

                        return;
                    }
                    await((IGuildUser)user).AddRoleAsync(role);
                    await ReplyAsync("", false,
                                     EmbedHelper.CreateEmbed("Givethem", $"Successfully added {user.Mention} to **{role.Name}**",
                                                             Color.Green));

                    success = true;
                }
            }
            if (!success)
            {
                await ReplyAsync("", false,
                                 EmbedHelper.CreateEmbed("Givethem - Error", "That role cannot be added.", Color.Orange));
            }
        }
Example #12
0
        public async Task GiveRoleAsync([Remainder][Summary("Role")] string rolename)
        {
            try
            {
                var success = false;
                rolename = rolename.Trim(' ');
                var user          = Context.User;
                var giveable      = _db.GetGiveableRoles(Context.Guild.Id);
                var upperGiveable = giveable.ConvertAll(x => x.ToUpper());
                if (upperGiveable.Contains(rolename.ToUpper()))
                {
                    var role = Context.Guild.Roles.FirstOrDefault(x => string.Equals(x.Name.ToString(), rolename,
                                                                                     StringComparison.CurrentCultureIgnoreCase));
                    if (user == null)
                    {
                        await ReplyAsync("", false,
                                         EmbedHelper.CreateEmbed("Could not give role", "User not found", Color.Orange));

                        return;
                    }
                    if (user is IGuildUser guildUser)
                    {
                        await guildUser.AddRoleAsync(role);
                    }


                    await ReplyAsync("", false,
                                     EmbedHelper.CreateEmbed("Giveme", $"Successfully added {user.Mention} to **{role.Name}**",
                                                             Color.Green));

                    success = true;
                }
                if (!success)
                {
                    var entries = Context.Guild.Roles.ToList().ConvertAll(x => x.Mention);
                    if (entries.Contains(rolename))
                    {
                        var role = Context.Guild.Roles.FirstOrDefault(x => string.Equals(x.Mention, rolename,
                                                                                         StringComparison.CurrentCultureIgnoreCase));
                        if (user == null)
                        {
                            await ReplyAsync("", false,
                                             EmbedHelper.CreateEmbed("Could not give role", "User not found", Color.Orange));

                            return;
                        }
                        if (user is IGuildUser guildUser)
                        {
                            await guildUser.AddRoleAsync(role);
                        }
                        await ReplyAsync("", false,
                                         EmbedHelper.CreateEmbed("Giveme", $"Successfully added {user.Mention} to **{role.Name}**",
                                                                 Color.Green));

                        success = true;
                    }
                }
                if (!success)
                {
                    await ReplyAsync("", false,
                                     EmbedHelper.CreateEmbed("Could not give role", "That role cannot be added.", Color.Orange));
                }
            }
            catch
            {
                await ReplyAsync("", false,
                                 EmbedHelper.CreateEmbed("!giveme - Error",
                                                         "The HonaBot role is below the role you are trying to obtain. Notify an admin to move HonaBot higher in the roles hierarchy.",
                                                         Color.Orange));
            }
        }
Example #13
0
 public async Task Uptime()
 {
     await ReplyAsync("", false, EmbedHelper.CreateEmbed($"Uptime: {_botStats.UpTime}", Color.Gold));
 }
Example #14
0
 public async Task Stats()
 {
     await ReplyAsync("", false, EmbedHelper.CreateEmbed($"Commands issued: {_botStats.CommandsCount}", Color.Gold));
 }
Example #15
0
 public async Task GetAnnouncementChannel()
 {
     await ReplyAsync("", false, EmbedHelper.CreateEmbed(_db.GetAnnouncementChannel(Context.Guild.Id).ToString(), Color.Gold));
 }
Example #16
0
 public async Task Embed([Remainder] string text)
 {
     await ReplyAsync("", false, EmbedHelper.CreateEmbed(text, Color.Gold));
 }
Example #17
0
 public async Task SayHelpAsync(int page = 0)
 {
     // ReplyAsync is a method on ModuleBase
     await ReplyAsync("", false, EmbedHelper.CreateEmbed("Help", HelpPage, Color.Gold));
 }