diff --git a/Commands/Misc.cs b/Commands/Misc.cs index af34ed9..16a5529 100644 --- a/Commands/Misc.cs +++ b/Commands/Misc.cs @@ -106,36 +106,5 @@ namespace dotbot.Commands await ReplyAsync(@"¯\\\_(ツ)\_/¯"); } - - [Command("noice")] - public async Task Noice() - { - await ReplyAsync(@" - :ok_hand: :joy: - :ok_hand::joy: -  :joy: - :joy::ok_hand: - :joy: :ok_hand: -:joy:  :ok_hand: -:joy:  :ok_hand: - :joy: :ok_hand: - :joy: :ok_hand: -  :ok_hand: - :ok_hand: :joy: - :ok_hand:  :joy: -:ok_hand:  :joy: -:ok_hand: :joy: - :ok_hand::joy: -  :joy: - :joy::ok_hand: - :joy: :ok_hand: -:joy:  :ok_hand: -:joy:  :ok_hand: - :joy: :ok_hand: - :joy: :ok_hand: -  :ok_hand:"); - } - - } } diff --git a/Commands/Polls.cs b/Commands/Polls.cs new file mode 100644 index 0000000..379fbfa --- /dev/null +++ b/Commands/Polls.cs @@ -0,0 +1,63 @@ +using Discord; +using Discord.Commands; +using dotbot.Services; +using Microsoft.Extensions.Configuration; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace dotbot.Commands +{ + [Group("poll")] + public class Polls : ModuleBase + { + private Dictionary _polls; + private IConfigurationRoot _config; + + public Polls(PollService polls, IConfigurationRoot config) + { + _polls = polls.currentPolls; + _config = config; + } + + [Command] + [Priority(0)] + [Summary("create a new poll")] + public async Task CreatePoll() + { + var pollId = Context.Channel.Id; + if (_polls.ContainsKey(pollId)) + { + await ReplyAsync($"add some more options or start the poll with `{_config["prefix"]}poll start`"); + } + else + { + _polls[pollId] = new Poll + { + Owner = Context.User, + IsOpen = false, + }; + await ReplyAsync($"you started a new poll. respond with some options and then start the poll with `{_config["prefix"]}poll start`"); + } + } + + + [Command("start")] + [Priority(1)] + [Summary("starts a poll!")] + public async Task StartPoll() + { + var pollId = Context.Channel.Id; + if (_polls.ContainsKey(pollId) && Context.User == _polls[pollId].Owner) + { + foreach (var o in _polls[pollId].Options) + { + var opt = await ReplyAsync($"{o.Text}"); + await opt.AddReactionAsync(Emote.Parse(":thumbsup:")); + } + _polls[pollId].IsOpen = true; + } + else await ReplyAsync($"no poll ready to start"); + } + + } +} diff --git a/Commands/UnicodeFonts.cs b/Commands/UnicodeFonts.cs new file mode 100644 index 0000000..e7a5516 --- /dev/null +++ b/Commands/UnicodeFonts.cs @@ -0,0 +1,126 @@ +using Discord.Commands; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace dotbot.Commands +{ + public class UnicodeFonts : ModuleBase + { + public class UnicodeFont + { + public string Uppers { get; set; } + public string Lowers { get; set; } + public string Nums { get; set; } + } + + public static Dictionary Fonts; + + public UnicodeFonts() + { + Fonts = new Dictionary + { + ["full"] = new UnicodeFont + { + Uppers = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + Lowers = "abcdefghijklmnopqrstuvwxyz", + Nums = "0123456789", + }, + ["mono"] = new UnicodeFont + { + Uppers = "𝙰𝙱𝙲𝙳𝙴𝙵𝙶𝙷𝙸𝙹𝙺𝙻𝙼𝙽𝙾𝙿𝚀𝚁𝚂𝚃𝚄𝚅𝚆𝚇𝚈𝚉", + Lowers = "𝚊𝚋𝚌𝚍𝚎𝚏𝚐𝚑𝚒𝚓𝚔𝚕𝚖𝚗𝚘𝚙𝚚𝚛𝚜𝚝𝚞𝚟𝚠𝚡𝚢𝚣", + Nums = "𝟶𝟷𝟸𝟹𝟺𝟻𝟼𝟽𝟾𝟿", + }, + ["flipped"] = new UnicodeFont + { + Uppers = "ɐqɔpǝɟƃɥıɾʞןɯuodbɹsʇn𐌡ʍxʎz", + Lowers = "ɐqɔpǝɟƃɥıɾʞןɯuodbɹsʇnʌʍxʎz", + Nums = "0123456789", + }, + ["reversed"] = new UnicodeFont + { + Uppers = "AdↃbƎꟻGHIJK⅃MᴎOꟼpᴙꙄTUVWXYZ", + Lowers = "AdↄbɘꟻgHijklmᴎoqpᴙꙅTUvwxYz", + Nums = "0߁23456789", + }, + ["cyrillic"] = new UnicodeFont + { + Uppers = "αв¢∂єƒﻭнιנкℓмησρ۹яѕтυνωχуչ", + Lowers = "αв¢∂єƒﻭнιנкℓмησρ۹яѕтυνωχуչ", + Nums = "0123456789", + }, + ["slashed"] = new UnicodeFont + { + Uppers = "ȺɃȻĐɆFǤĦƗɈꝀŁMNØⱣꝖɌSŦᵾVWXɎƵ", + Lowers = "Ⱥƀȼđɇfǥħɨɉꝁłmnøᵽꝗɍsŧᵾvwxɏƶ", + Nums = "01ƻ3456789", + }, + ["script"] = new UnicodeFont + { + Uppers = "𝓐𝓑𝓒𝓓𝓔𝓕𝓖𝓗𝓘𝓙𝓚𝓛𝓜𝓝𝓞𝓟𝓠𝓡𝓢𝓣𝓤𝓥𝓦𝓧𝓨𝓩", + Lowers = "𝓪𝓫𝓬𝓭𝓮𝓯𝓰𝓱𝓲𝓳𝓴𝓵𝓶𝓷𝓸𝓹𝓺𝓻𝓼𝓽𝓾𝓿𝔀𝔁𝔂𝔃", + Nums = "𝟎𝟏𝟐𝟑𝟒𝟓𝟔𝟕𝟖𝟗", + }, + ["gothic"] = new UnicodeFont + { + Uppers = "𝕬𝕭𝕮𝕯𝕰𝕱𝕲𝕳𝕴𝕵𝕶𝕷𝕸𝕹𝕺𝕻𝕼𝕽𝕾𝕿𝖀𝖁𝖂𝖃𝖄𝖅", + Lowers = "𝖆𝖇𝖈𝖉𝖊𝖋𝖌𝖍𝖎𝖏𝖐𝖑𝖒𝖓𝖔𝖕𝖖𝖗𝖘𝖙𝖚𝖛𝖜𝖝𝖞𝖟", + Nums = "𝟘𝟙𝟚𝟛𝟜𝟝𝟞𝟟𝟠𝟡", + }, + ["vaporwave"] = new UnicodeFont + { + Uppers = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + Lowers = "abcdefghijklmnopqrstuvwxyz", + Nums = "0123456789", + }, + }; + } + + + [Command("block")] + [Summary("block text!")] + public async Task BlockText([Remainder] string text) + { + var Nums = new string[] { ":zero:", ":one:", ":two:", ":three:", ":four:", ":five:", ":six:", ":seven:", ":eight:", ":nine:" }; + var res = new StringBuilder(); + foreach (var c in text.ToCharArray()) + { + res.Append(Char.IsDigit(c) ? $"{Nums[c - '0']} " : Char.IsLetter(c) ? $":regional_indicator_{c.ToString().ToLower()}: " : ""); + } + await ReplyAsync(res.ToString()); + } + + + [Command("fonts")] + [Alias("fontlist")] + public async Task ListFonts() + { + await base.ReplyAsync($"here are the available unicode fonts:```{string.Join(", ", Fonts.Keys)}```"); + } + + + public static string ConvertFont(string fontName, string message) + { + var res = new StringBuilder(); + foreach (var c in message.ToCharArray()) + { + switch (c) + { + case char n when (c >= '0' && c <= '9'): + res.Append($"{Fonts[fontName].Nums[n - '0']} "); + break; + case char n when (c >= 'a' && c <= 'z'): + res.Append($"{Fonts[fontName].Lowers[n - 'a']} "); + break; + case char n when (c >= 'A' && c <= 'Z'): + res.Append($"{Fonts[fontName].Uppers[n - 'z']} "); + break; + } + } + return res.ToString(); + } + + } +} diff --git a/Commands/Weather.cs b/Commands/Weather.cs index aec889b..424d17f 100644 --- a/Commands/Weather.cs +++ b/Commands/Weather.cs @@ -113,7 +113,7 @@ namespace dotbot.Commands public class Wind { public double speed { get; set; } - public int deg { get; set; } + public double deg { get; set; } } public Wind wind { get; set; } public class Sys diff --git a/Migrations/20171210011038_WindDegDouble.Designer.cs b/Migrations/20171210011038_WindDegDouble.Designer.cs new file mode 100644 index 0000000..b7b16be --- /dev/null +++ b/Migrations/20171210011038_WindDegDouble.Designer.cs @@ -0,0 +1,80 @@ +// +using dotbot.Core; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage; +using System; + +namespace dotbot.Migrations +{ + [DbContext(typeof(DotbotDb))] + [Migration("20171210011038_WindDegDouble")] + partial class WindDegDouble + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.0.1-rtm-125"); + + modelBuilder.Entity("dotbot.Core.Definition", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Def"); + + b.HasKey("Id"); + + b.ToTable("Defs"); + }); + + modelBuilder.Entity("dotbot.Core.Email", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EmailAddress"); + + b.HasKey("Id"); + + b.ToTable("Emails"); + }); + + modelBuilder.Entity("dotbot.Core.Image", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("FilePath"); + + b.HasKey("Id"); + + b.ToTable("Images"); + }); + + modelBuilder.Entity("dotbot.Core.UserLocation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("City"); + + b.Property("CityId"); + + b.Property("Lat"); + + b.Property("Lng"); + + b.Property("TimeZone"); + + b.HasKey("Id"); + + b.ToTable("UserLocations"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20171210011038_WindDegDouble.cs b/Migrations/20171210011038_WindDegDouble.cs new file mode 100644 index 0000000..972f91c --- /dev/null +++ b/Migrations/20171210011038_WindDegDouble.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using System; +using System.Collections.Generic; + +namespace dotbot.Migrations +{ + public partial class WindDegDouble : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/Program.cs b/Program.cs index 3fe7c58..51e3292 100644 --- a/Program.cs +++ b/Program.cs @@ -40,6 +40,7 @@ namespace dotbot .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton(_config); diff --git a/Services/CommandHandlerService.cs b/Services/CommandHandlerService.cs index 72ffc0a..b944f50 100644 --- a/Services/CommandHandlerService.cs +++ b/Services/CommandHandlerService.cs @@ -5,6 +5,8 @@ using System; using System.Threading.Tasks; using dotbot.Core; using System.Linq; +using dotbot.Commands; +using System.Collections.Generic; namespace dotbot.Services { @@ -15,19 +17,22 @@ namespace dotbot.Services private readonly CommandService _commands; private readonly IConfigurationRoot _config; private readonly IServiceProvider _provider; + private Dictionary _polls; public CommandHandlerService( DiscordSocketClient discord, CommandService commands, IConfigurationRoot config, IServiceProvider provider, - DotbotDb db + DotbotDb db, + PollService polls ) { _discord = discord; _commands = commands; _config = config; _provider = provider; _db = db; + _polls = polls.currentPolls; _discord.MessageReceived += OnMessageReceivedAsync; } @@ -47,26 +52,41 @@ namespace dotbot.Services var result = await _commands.ExecuteAsync(context, argPos, _provider); // Execute the command if (result.IsSuccess) return; + if (!result.IsSuccess && result.ToString() != "UnknownCommand: Unknown command.") + await context.Channel.SendMessageAsync(result.ToString()); + if (msg.HasStringPrefix(_config["prefix"], ref argPos)) - { - var key = msg.Content.Substring(_config["prefix"].Length); + { // check for other conditions + var key = msg.Content.Substring(_config["prefix"].Length).Split(' ').First(); + if (_db.Defs.Any(d => d.Id == key)) - { + { // get def await context.Channel.SendMessageAsync($"**{key}**: {_db.Defs.Find(key).Def}"); - return; } - if (_db.Images.Any(i => i.Id == key)) - { + else if (_db.Images.Any(i => i.Id == key)) + { // get img await context.Channel.TriggerTypingAsync(); await context.Message.DeleteAsync(); var img = _db.Images.Find(key); await context.Channel.SendFileAsync($"UploadedImages/{img.FilePath}", $"{img.Id} by {context.User.Mention}"); - return; + } + else if (UnicodeFonts.Fonts.Any(f => f.Key == key)) + { // convert font + Console.WriteLine(key); + var msgtext = msg.Content.Substring(msg.Content.IndexOf(" ")); + Console.WriteLine(msgtext); + await context.Channel.SendMessageAsync(UnicodeFonts.ConvertFont(key, msgtext)); } } - - if (!result.IsSuccess && result.ToString() != "UnknownCommand: Unknown command.") - await context.Channel.SendMessageAsync(result.ToString()); + } + else + { // add poll options + var id = context.Channel.Id; + if (_polls.ContainsKey(id) && _polls[id].Owner == context.User && !_polls[id].IsOpen) + { + _polls[id].Options.Add(new PollOption { Text = msg.Content }); + await context.Channel.SendMessageAsync($"{msg.Content} added!"); + } } } } diff --git a/Services/PollService.cs b/Services/PollService.cs new file mode 100644 index 0000000..839a1a2 --- /dev/null +++ b/Services/PollService.cs @@ -0,0 +1,32 @@ +using Discord; +using System.Collections.Generic; +using System.Linq; + +namespace dotbot.Services +{ + public class PollService + { + public Dictionary currentPolls; + + public PollService() + { + currentPolls = new Dictionary(); + } + } + + public class Poll + { + public List Options { get; set; } + public bool IsOpen { get; set; } + public IUser Owner { get; set; } + + public PollOption GetWinner => Options.OrderBy(o => o.Votes).Last(); + + } + + public class PollOption + { + public string Text { get; set; } + public int Votes { get; set; } + } +}