diff --git a/src/NadekoBot/_Modules/Gambling/Commands/AnimalRacing.cs b/src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs similarity index 100% rename from src/NadekoBot/_Modules/Gambling/Commands/AnimalRacing.cs rename to src/NadekoBot/Modules/Gambling/Commands/AnimalRacing.cs diff --git a/src/NadekoBot/_Modules/Gambling/DiceRollCommand.cs b/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs similarity index 98% rename from src/NadekoBot/_Modules/Gambling/DiceRollCommand.cs rename to src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs index 2ee94a90..6a34d922 100644 --- a/src/NadekoBot/_Modules/Gambling/DiceRollCommand.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/DiceRollCommand.cs @@ -3,15 +3,13 @@ using NadekoBot.Classes; using NadekoBot.Extensions; using System; using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Imaging; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace NadekoBot.Modules.Gambling { - internal class DiceRollCommand : DiscordCommand + public partial class DiceRollCommands { public DiceRollCommand(DiscordModule module) : base(module) { } diff --git a/src/NadekoBot/_Modules/Gambling/DrawCommand.cs b/src/NadekoBot/Modules/Gambling/Commands/DrawCommand.cs similarity index 100% rename from src/NadekoBot/_Modules/Gambling/DrawCommand.cs rename to src/NadekoBot/Modules/Gambling/Commands/DrawCommand.cs diff --git a/src/NadekoBot/_Modules/Gambling/FlipCoinCommand.cs b/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs similarity index 100% rename from src/NadekoBot/_Modules/Gambling/FlipCoinCommand.cs rename to src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs diff --git a/src/NadekoBot/_Modules/Gambling/GamblingModule.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs similarity index 86% rename from src/NadekoBot/_Modules/Gambling/GamblingModule.cs rename to src/NadekoBot/Modules/Gambling/Gambling.cs index 46fe80c6..449b452e 100644 --- a/src/NadekoBot/_Modules/Gambling/GamblingModule.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -1,53 +1,47 @@ using Discord; using Discord.Commands; -using Discord.Modules; -using NadekoBot.Classes; -using NadekoBot.DataModels; +using NadekoBot.Attributes; using NadekoBot.Extensions; -using NadekoBot.Modules.Gambling.Commands; -using NadekoBot.Modules.Permissions.Classes; using System; using System.Linq; using System.Text; +using System.Threading.Tasks; +using NadekoBot.Services; +//todo DB namespace NadekoBot.Modules.Gambling { - internal class GamblingModule : DiscordModule + [Module("$", AppendSpace = false)] + public partial class Gambling : DiscordModule { - public GamblingModule() + public Gambling(ILocalization loc, CommandService cmds, IBotConfiguration config, IDiscordClient client) : base(loc, cmds, config, client) { - commands.Add(new DrawCommand(this)); - commands.Add(new FlipCoinCommand(this)); - commands.Add(new DiceRollCommand(this)); - commands.Add(new AnimalRacing(this)); } - public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Gambling; + [LocalizedCommand, LocalizedDescription, LocalizedSummary] + [RequireContext(ContextType.Guild)] + public async Task Raffle(IMessage imsg, [Remainder] IRole role = null) + { + var channel = imsg.Channel as ITextChannel; + role = role ?? channel.Guild.EveryoneRole; + + var members = (await role.Members()).Where(u => u.Status == UserStatus.Online); + var membersArray = members as IUser[] ?? members.ToArray(); + var usr = membersArray[new Random().Next(0, membersArray.Length)]; + await imsg.Channel.SendMessageAsync($"**Raffled user:** {usr.Username} (id: {usr.Id})").ConfigureAwait(false); + + } public override void Install(ModuleManager manager) { manager.CreateCommands("", cgb => { - cgb.AddCheck(PermissionChecker.Instance); - - commands.ForEach(com => com.Init(cgb)); - cgb.CreateCommand(Prefix + "raffle") .Description($"Prints a name and ID of a random user from the online list from the (optional) role. | `{Prefix}raffle` or `{Prefix}raffle RoleName`") .Parameter("role", ParameterType.Optional) .Do(async e => { - var arg = string.IsNullOrWhiteSpace(e.GetArg("role")) ? "@everyone" : e.GetArg("role"); - var role = e.Server.FindRoles(arg).FirstOrDefault(); - if (role == null) - { - await imsg.Channel.SendMessageAsync("💢 Role not found.").ConfigureAwait(false); - return; - } - var members = role.Members.Where(u => u.Status == UserStatus.Online); // only online - var membersArray = members as User[] ?? members.ToArray(); - var usr = membersArray[new Random().Next(0, membersArray.Length)]; - await imsg.Channel.SendMessageAsync($"**Raffled user:** {usr.Name} (id: {usr.Id})").ConfigureAwait(false); + }); cgb.CreateCommand(Prefix + "$$") diff --git a/src/NadekoBot/_Modules/Gambling/Helpers/Cards.cs b/src/NadekoBot/Modules/Gambling/Helpers/Cards.cs similarity index 100% rename from src/NadekoBot/_Modules/Gambling/Helpers/Cards.cs rename to src/NadekoBot/Modules/Gambling/Helpers/Cards.cs