Merge pull request #7 from pizzaandcoffee/dice-and-fortune
Dice and Fortune Commands
This commit is contained in:
commit
ee4c09e7ea
7 changed files with 9892 additions and 13 deletions
48
Geekbot.net/Lib/Fortunes.cs
Normal file
48
Geekbot.net/Lib/Fortunes.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Geekbot.net.Lib
|
||||
{
|
||||
class Fortunes : IFortunes
|
||||
{
|
||||
private string[] fortuneArray;
|
||||
private int totalFortunes;
|
||||
private Random rnd;
|
||||
|
||||
public Fortunes()
|
||||
{
|
||||
var path = Path.GetFullPath("./fortunes");
|
||||
if (File.Exists(path))
|
||||
{
|
||||
var rawFortunes= File.ReadAllText(path);
|
||||
fortuneArray = rawFortunes.Split("%");
|
||||
totalFortunes = fortuneArray.Length;
|
||||
rnd = new Random();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Fortunes File not found");
|
||||
Console.WriteLine($"Path should be {path}");
|
||||
}
|
||||
}
|
||||
|
||||
public string GetRandomFortune()
|
||||
{
|
||||
return fortuneArray[rnd.Next(0, totalFortunes)];
|
||||
}
|
||||
|
||||
public string GetFortune(int id)
|
||||
{
|
||||
return fortuneArray[id];
|
||||
}
|
||||
}
|
||||
|
||||
public interface IFortunes
|
||||
{
|
||||
string GetRandomFortune();
|
||||
string GetFortune(int id);
|
||||
}
|
||||
}
|
54
Geekbot.net/Modules/Dice.cs
Normal file
54
Geekbot.net/Modules/Dice.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class Dice : ModuleBase
|
||||
{
|
||||
private readonly Random rnd;
|
||||
public Dice(Random RandomClient)
|
||||
{
|
||||
rnd = RandomClient;
|
||||
}
|
||||
|
||||
[Command("dice", RunMode = RunMode.Async), Summary("Roll a dice.")]
|
||||
public async Task RollCommand([Remainder, Summary("1d20, 1d6, 2d3, etc...")] string diceType = "1d6")
|
||||
{
|
||||
var dice = diceType.Split("d");
|
||||
|
||||
if (dice.Length != 2
|
||||
|| !int.TryParse(dice[0], out int times)
|
||||
|| !int.TryParse(dice[1], out int max))
|
||||
{
|
||||
await ReplyAsync("That is not a valid dice, examples are: 1d20, 1d6, 2d10, 5d12, etc...");
|
||||
return;
|
||||
}
|
||||
Console.WriteLine($"Max: {max} - Times {times}");
|
||||
if (times > 10 && !(times < 0))
|
||||
{
|
||||
await ReplyAsync("You can only roll between 1 and 10 dices");
|
||||
return;
|
||||
}
|
||||
if (max > 100 && !(max < 1))
|
||||
{
|
||||
await ReplyAsync("The dice must have between 1 and 100 sides");
|
||||
return;
|
||||
}
|
||||
var eb = new EmbedBuilder();
|
||||
eb.WithAuthor(new EmbedAuthorBuilder()
|
||||
.WithIconUrl(Context.User.GetAvatarUrl())
|
||||
.WithName(Context.User.Username));
|
||||
eb.WithColor(new Color(133, 189, 219));
|
||||
eb.Title = $":game_die: Dice Roll - Type {diceType} :game_die:";
|
||||
for (var i = 0; i < times; i++)
|
||||
{
|
||||
eb.AddInlineField($"Dice {i+1}", rnd.Next(1, max));
|
||||
}
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
}
|
||||
}
|
22
Geekbot.net/Modules/Fortune.cs
Normal file
22
Geekbot.net/Modules/Fortune.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
{
|
||||
public class Fortune : ModuleBase
|
||||
{
|
||||
private readonly IFortunes fortunes;
|
||||
public Fortune(IFortunes fortunes)
|
||||
{
|
||||
this.fortunes = fortunes;
|
||||
}
|
||||
|
||||
[Command("fortune", RunMode = RunMode.Async), Summary("Get a random fortune")]
|
||||
public async Task GetAFortune()
|
||||
{
|
||||
await ReplyAsync(fortunes.GetRandomFortune());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Geekbot.net.Modules
|
||||
|
@ -38,12 +37,5 @@ namespace Geekbot.net.Modules
|
|||
await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number);
|
||||
}
|
||||
}
|
||||
|
||||
[Command("dice", RunMode = RunMode.Async), Summary("Roll a dice")]
|
||||
public async Task DiceCommand([Summary("The highest number on the dice")] int max = 6)
|
||||
{
|
||||
var number = rnd.Next(1, max);
|
||||
await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -32,13 +32,14 @@ namespace Geekbot.net
|
|||
Console.WriteLine(@"| |_| | |___| |___| . \| |_) | |_| || |");
|
||||
Console.WriteLine(@" \____|_____|_____|_|\_\____/ \___/ |_|");
|
||||
Console.WriteLine("=========================================");
|
||||
Console.WriteLine("Starting...");
|
||||
Console.WriteLine("* Starting...");
|
||||
|
||||
new Program().MainAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public async Task MainAsync()
|
||||
{
|
||||
Console.WriteLine("* Initing Stuff");
|
||||
client = new DiscordSocketClient();
|
||||
commands = new CommandService();
|
||||
|
||||
|
@ -67,11 +68,13 @@ namespace Geekbot.net
|
|||
}
|
||||
|
||||
services = new ServiceCollection();
|
||||
var fortunes = new Fortunes();
|
||||
var RandomClient = new Random();
|
||||
services.AddSingleton<IFortunes>(fortunes);
|
||||
services.AddSingleton(RandomClient);
|
||||
services.AddSingleton(redis);
|
||||
|
||||
Console.WriteLine("Connecting to Discord...");
|
||||
Console.WriteLine("* Connecting to Discord");
|
||||
|
||||
await Login();
|
||||
|
||||
|
@ -88,9 +91,9 @@ namespace Geekbot.net
|
|||
if (isConneted)
|
||||
{
|
||||
await client.SetGameAsync("Ping Pong");
|
||||
Console.WriteLine($"Now Connected to {client.Guilds.Count} Servers");
|
||||
Console.WriteLine($"* Now Connected to {client.Guilds.Count} Servers");
|
||||
|
||||
Console.WriteLine("Registering Stuff");
|
||||
Console.WriteLine("* Registering Stuff");
|
||||
|
||||
client.MessageReceived += HandleCommand;
|
||||
client.MessageReceived += HandleMessageReceived;
|
||||
|
@ -98,7 +101,7 @@ namespace Geekbot.net
|
|||
await commands.AddModulesAsync(Assembly.GetEntryAssembly());
|
||||
servicesProvider = services.BuildServiceProvider();
|
||||
|
||||
Console.WriteLine("Done and ready for use...\n");
|
||||
Console.WriteLine("* Done and ready for use\n");
|
||||
}
|
||||
}
|
||||
catch (AggregateException)
|
||||
|
|
9760
Geekbot.net/fortunes
Normal file
9760
Geekbot.net/fortunes
Normal file
File diff suppressed because it is too large
Load diff
BIN
derp.ico
BIN
derp.ico
Binary file not shown.
Before Width: | Height: | Size: 361 KiB |
Loading…
Reference in a new issue