Bug fixes in polls, emoji stuff and quotes

This commit is contained in:
Runebaas 2017-11-08 19:19:43 +01:00
parent f96954a7e1
commit 0e217b8db1
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
4 changed files with 39 additions and 10 deletions

View file

@ -25,8 +25,14 @@ namespace Geekbot.net.Commands
try try
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
var emojis = _emojiConverter.textToEmoji(text);
if (emojis.Length > 1999)
{
await ReplyAsync("I can't take that much at once!");
return;
}
await ReplyAsync($"*{Context.User.Username}#{Context.User.Discriminator} said:*"); await ReplyAsync($"*{Context.User.Username}#{Context.User.Discriminator} said:*");
await ReplyAsync(_emojiConverter.textToEmoji(text)); await ReplyAsync(emojis);
} }
catch (Exception e) catch (Exception e)
{ {

View file

@ -56,6 +56,12 @@ namespace Geekbot.net.Commands
{ {
try try
{ {
var currentPoll = GetCurrentPoll();
if (currentPoll.Question != null && !currentPoll.IsFinshed)
{
await ReplyAsync("You have not finished you last poll yet. To finish it use `!poll end`");
return;
}
var pollList = rawPollString.Split(';').ToList(); var pollList = rawPollString.Split(';').ToList();
if (pollList.Count <= 2) if (pollList.Count <= 2)
{ {
@ -121,6 +127,9 @@ namespace Geekbot.net.Commands
sb.AppendLine($"{result.VoteCount} - {result.Option}"); sb.AppendLine($"{result.VoteCount} - {result.Option}");
} }
await ReplyAsync(sb.ToString()); await ReplyAsync(sb.ToString());
currentPoll.IsFinshed = true;
var pollJson = JsonConvert.SerializeObject(currentPoll);
_redis.HashSet($"{Context.Guild.Id}:Polls", new HashEntry[] {new HashEntry(Context.Channel.Id, pollJson)});
} }
catch (Exception e) catch (Exception e)
{ {
@ -146,6 +155,8 @@ namespace Geekbot.net.Commands
var message = (IUserMessage)(await Context.Channel.GetMessageAsync(poll.MessageId)); var message = (IUserMessage)(await Context.Channel.GetMessageAsync(poll.MessageId));
var results = new List<PollResult>(); var results = new List<PollResult>();
foreach (var r in message.Reactions) foreach (var r in message.Reactions)
{
try
{ {
var option = int.Parse(r.Key.Name.ToCharArray()[0].ToString()); var option = int.Parse(r.Key.Name.ToCharArray()[0].ToString());
var result = new PollResult() var result = new PollResult()
@ -155,6 +166,8 @@ namespace Geekbot.net.Commands
}; };
results.Add(result); results.Add(result);
} }
catch {}
}
results.Sort((x,y) => y.VoteCount.CompareTo(x.VoteCount)); results.Sort((x,y) => y.VoteCount.CompareTo(x.VoteCount));
return results; return results;
} }

View file

@ -55,6 +55,11 @@ namespace Geekbot.net.Commands
await ReplyAsync("You can't save your own quotes..."); await ReplyAsync("You can't save your own quotes...");
return; return;
} }
if (user.IsBot)
{
await ReplyAsync("You can't save quotes by a bot...");
return;
}
var lastMessage = await getLastMessageByUser(user); var lastMessage = await getLastMessageByUser(user);
var quote = createQuoteObject(lastMessage); var quote = createQuoteObject(lastMessage);
var quoteStore = JsonConvert.SerializeObject(quote); var quoteStore = JsonConvert.SerializeObject(quote);
@ -81,6 +86,11 @@ namespace Geekbot.net.Commands
await ReplyAsync("You can't save your own quotes..."); await ReplyAsync("You can't save your own quotes...");
return; return;
} }
if (message.Author.IsBot)
{
await ReplyAsync("You can't save quotes by a bot...");
return;
}
var quote = createQuoteObject(message); var quote = createQuoteObject(message);
var quoteStore = JsonConvert.SerializeObject(quote); var quoteStore = JsonConvert.SerializeObject(quote);
redis.SetAdd($"{Context.Guild.Id}:Quotes", quoteStore); redis.SetAdd($"{Context.Guild.Id}:Quotes", quoteStore);

View file

@ -61,10 +61,10 @@ namespace Geekbot.net.Lib
['2'] = ":two:", ['2'] = ":two:",
['3'] = ":three:", ['3'] = ":three:",
['4'] = ":four:", ['4'] = ":four:",
['5'] = ":five", ['5'] = ":five:",
['6'] = ":six", ['6'] = ":six:",
['7'] = ":seven:", ['7'] = ":seven:",
['8'] = ":eight", ['8'] = ":eight:",
['9'] = ":nine:", ['9'] = ":nine:",
[' '] = " " [' '] = " "
}; };