2016-03-25 11:48:22 +00:00
using Discord ;
using Discord.Commands ;
using Discord.Modules ;
2016-03-26 02:25:03 +00:00
using NadekoBot.Classes ;
2016-05-11 09:37:19 +00:00
using NadekoBot.DataModels ;
2016-03-25 11:48:22 +00:00
using NadekoBot.Extensions ;
2016-04-14 22:17:29 +00:00
using NadekoBot.Modules.Permissions.Classes ;
2016-03-26 02:25:03 +00:00
using System ;
2016-03-25 11:48:22 +00:00
using System.Linq ;
2016-05-11 09:37:19 +00:00
using System.Text ;
2016-03-25 11:48:22 +00:00
namespace NadekoBot.Modules.Gambling
{
internal class GamblingModule : DiscordModule
{
public GamblingModule ( )
{
commands . Add ( new DrawCommand ( this ) ) ;
commands . Add ( new FlipCoinCommand ( this ) ) ;
commands . Add ( new DiceRollCommand ( this ) ) ;
}
public override string Prefix { get ; } = NadekoBot . Config . CommandPrefixes . Gambling ;
public override void Install ( ModuleManager manager )
{
manager . CreateCommands ( "" , cgb = >
{
2016-04-14 22:17:29 +00:00
cgb . AddCheck ( PermissionChecker . Instance ) ;
2016-03-25 11:48:22 +00:00
commands . ForEach ( com = > com . Init ( cgb ) ) ;
cgb . CreateCommand ( Prefix + "raffle" )
2016-03-26 02:25:03 +00:00
. Description ( "Prints a name and ID of a random user from the online list from the (optional) role." )
. Parameter ( "role" , ParameterType . Optional )
2016-05-11 10:48:50 +00:00
. 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 e . Channel . SendMessage ( "💢 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 e . Channel . SendMessage ( $"**Raffled user:** {usr.Name} (id: {usr.Id})" ) . ConfigureAwait ( false ) ;
} ) ;
2016-03-30 10:46:02 +00:00
2016-03-25 11:48:22 +00:00
cgb . CreateCommand ( Prefix + "$$" )
2016-05-13 17:30:11 +00:00
. Description ( string . Format ( "Check how much {0}s a person has. (Defaults to yourself)\n**Usage**:`{1}$$` or `{1}$$ @Someone`" ,
NadekoBot . Config . CurrencyName , Prefix ) )
2016-05-11 10:48:50 +00:00
. Parameter ( "all" , ParameterType . Unparsed )
. Do ( async e = >
{
var usr = e . Message . MentionedUsers . FirstOrDefault ( ) ? ? e . User ;
var pts = GetUserFlowers ( usr . Id ) ;
var str = $"{usr.Name} has {pts} {NadekoBot.Config.CurrencySign}" ;
await e . Channel . SendMessage ( str ) . ConfigureAwait ( false ) ;
} ) ;
2016-03-30 10:46:02 +00:00
2016-03-26 02:25:03 +00:00
cgb . CreateCommand ( Prefix + "give" )
2016-03-28 02:36:59 +00:00
. Description ( string . Format ( "Give someone a certain amount of {0}s" , NadekoBot . Config . CurrencyName ) )
2016-03-26 02:25:03 +00:00
. Parameter ( "amount" , ParameterType . Required )
. Parameter ( "receiver" , ParameterType . Unparsed )
. Do ( async e = >
{
var amountStr = e . GetArg ( "amount" ) ? . Trim ( ) ;
long amount ;
if ( ! long . TryParse ( amountStr , out amount ) | | amount < 0 )
return ;
var mentionedUser = e . Message . MentionedUsers . FirstOrDefault ( u = >
u . Id ! = NadekoBot . Client . CurrentUser . Id & &
u . Id ! = e . User . Id ) ;
if ( mentionedUser = = null )
return ;
var userFlowers = GetUserFlowers ( e . User . Id ) ;
if ( userFlowers < amount )
{
2016-04-18 21:38:19 +00:00
await e . Channel . SendMessage ( $"{e.User.Mention} You don't have enough {NadekoBot.Config.CurrencyName}s. You have only {userFlowers}{NadekoBot.Config.CurrencySign}." ) . ConfigureAwait ( false ) ;
2016-03-26 02:25:03 +00:00
return ;
}
2016-03-30 16:54:57 +00:00
FlowersHandler . RemoveFlowers ( e . User , "Gift" , ( int ) amount ) ;
2016-04-18 21:38:19 +00:00
await FlowersHandler . AddFlowersAsync ( mentionedUser , "Gift" , ( int ) amount ) . ConfigureAwait ( false ) ;
2016-03-26 02:25:03 +00:00
2016-04-18 21:38:19 +00:00
await e . Channel . SendMessage ( $"{e.User.Mention} successfully sent {amount} {NadekoBot.Config.CurrencyName}s to {mentionedUser.Mention}!" ) . ConfigureAwait ( false ) ;
2016-03-26 02:25:03 +00:00
} ) ;
2016-03-30 10:46:02 +00:00
cgb . CreateCommand ( Prefix + "award" )
2016-06-15 20:53:43 +00:00
. Description ( "Gives someone a certain amount of flowers. **Bot Owner Only!**\n**Usage**: `$award 100 @person`" )
2016-04-14 22:17:29 +00:00
. AddCheck ( SimpleCheckers . OwnerOnly ( ) )
2016-03-30 10:46:02 +00:00
. Parameter ( "amount" , ParameterType . Required )
. Parameter ( "receiver" , ParameterType . Unparsed )
. Do ( async e = >
{
var amountStr = e . GetArg ( "amount" ) ? . Trim ( ) ;
long amount ;
if ( ! long . TryParse ( amountStr , out amount ) | | amount < 0 )
return ;
var mentionedUser = e . Message . MentionedUsers . FirstOrDefault ( u = >
u . Id ! = NadekoBot . Client . CurrentUser . Id ) ;
if ( mentionedUser = = null )
return ;
2016-04-18 21:38:19 +00:00
await FlowersHandler . AddFlowersAsync ( mentionedUser , $"Awarded by bot owner. ({e.User.Name}/{e.User.Id})" , ( int ) amount ) . ConfigureAwait ( false ) ;
2016-03-30 10:46:02 +00:00
2016-04-18 21:38:19 +00:00
await e . Channel . SendMessage ( $"{e.User.Mention} successfully awarded {amount} {NadekoBot.Config.CurrencyName}s to {mentionedUser.Mention}!" ) . ConfigureAwait ( false ) ;
2016-03-30 10:46:02 +00:00
} ) ;
cgb . CreateCommand ( Prefix + "take" )
2016-06-15 20:53:43 +00:00
. Description ( "Takes a certain amount of flowers from someone. **Bot Owner Only!**" )
2016-04-14 22:17:29 +00:00
. AddCheck ( SimpleCheckers . OwnerOnly ( ) )
2016-03-30 10:46:02 +00:00
. Parameter ( "amount" , ParameterType . Required )
. Parameter ( "rektperson" , ParameterType . Unparsed )
. Do ( async e = >
{
var amountStr = e . GetArg ( "amount" ) ? . Trim ( ) ;
long amount ;
if ( ! long . TryParse ( amountStr , out amount ) | | amount < 0 )
return ;
var mentionedUser = e . Message . MentionedUsers . FirstOrDefault ( u = >
u . Id ! = NadekoBot . Client . CurrentUser . Id ) ;
if ( mentionedUser = = null )
return ;
2016-03-30 16:54:57 +00:00
FlowersHandler . RemoveFlowers ( mentionedUser , $"Taken by bot owner.({e.User.Name}/{e.User.Id})" , ( int ) amount ) ;
2016-03-30 10:46:02 +00:00
2016-04-18 21:38:19 +00:00
await e . Channel . SendMessage ( $"{e.User.Mention} successfully took {amount} {NadekoBot.Config.CurrencyName}s from {mentionedUser.Mention}!" ) . ConfigureAwait ( false ) ;
2016-03-30 10:46:02 +00:00
} ) ;
2016-05-11 09:37:19 +00:00
cgb . CreateCommand ( Prefix + "leaderboard" )
. Alias ( Prefix + "lb" )
. Do ( async e = >
{
var richestTemp = DbHandler . Instance . GetTopRichest ( ) ;
var richest = richestTemp as CurrencyState [ ] ? ? richestTemp . ToArray ( ) ;
if ( richest . Length = = 0 )
return ;
await e . Channel . SendMessage (
richest . Aggregate ( new StringBuilder (
2016-07-11 09:44:33 +00:00
$ @ "```xl
┏ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ┳ ━ ━ ━ ━ ━ ━ ━ ┓
┃ Id ┃ $ $ $ ┃
2016-05-11 09:37:19 +00:00
"),
( cur , cs ) = > cur . AppendLine (
2016-07-11 09:44:33 +00:00
$ @ "┣━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━┫
┃ { ( e . Server . Users . Where ( u = > u . Id = = ( ulong ) cs . UserId ) . FirstOrDefault ( ) ? . Name . TrimTo ( 18 , true ) ? ? cs . UserId . ToString ( ) ) , - 20 } ┃ { cs . Value , 5 } ┃ ")
) . ToString ( ) + "┗━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━┛```" ) ;
2016-05-11 09:37:19 +00:00
} ) ;
2016-03-25 11:48:22 +00:00
} ) ;
}
2016-03-26 02:25:03 +00:00
private static long GetUserFlowers ( ulong userId ) = >
Classes . DbHandler . Instance . GetStateByUserId ( ( long ) userId ) ? . Value ? ? 0 ;
2016-03-25 11:48:22 +00:00
}
}