Intial 1.0 commit

This commit is contained in:
Kwoth
2016-08-13 20:45:08 +02:00
parent 30ba68e073
commit f748bad188
648 changed files with 19608 additions and 55378 deletions

View File

@@ -0,0 +1,99 @@
//using Discord;
//using Discord.Commands;
//using NadekoBot.Classes;
//using NadekoBot.Extensions;
//using System;
//using System.Linq;
//using System.Text;
//namespace NadekoBot.Modules.Utility.Commands
//{
// class InfoCommands : DiscordCommand
// {
// public InfoCommands(DiscordModule module) : base(module)
// {
// }
// internal override void Init(CommandGroupBuilder cgb)
// {
// cgb.CreateCommand(Module.Prefix + "serverinfo")
// .Alias(Module.Prefix + "sinfo")
// .Description($"Shows info about the server the bot is on. If no channel is supplied, it defaults to current one. |`{Module.Prefix}sinfo Some Server`")
// .Parameter("server", ParameterType.Optional)
// .Do(async e =>
// {
// var servText = e.GetArg("server")?.Trim();
// var server = string.IsNullOrWhiteSpace(servText)
// ? e.Server
// : NadekoBot.Client.FindServers(servText).FirstOrDefault();
// if (server == null)
// return;
// var createdAt = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(server.Id >> 22);
// var sb = new StringBuilder();
// sb.AppendLine($"`Name:` **#{server.Name}**");
// sb.AppendLine($"`Owner:` **{server.Owner}**");
// sb.AppendLine($"`Id:` **{server.Id}**");
// sb.AppendLine($"`Icon Url:` **{await server.IconUrl.ShortenUrl().ConfigureAwait(false)}**");
// sb.AppendLine($"`TextChannels:` **{server.TextChannels.Count()}** `VoiceChannels:` **{server.VoiceChannels.Count()}**");
// sb.AppendLine($"`Members:` **{server.UserCount}** `Online:` **{server.Users.Count(u => u.Status == UserStatus.Online)}** (may be incorrect)");
// sb.AppendLine($"`Roles:` **{server.Roles.Count()}**");
// sb.AppendLine($"`Created At:` **{createdAt}**");
// if (server.CustomEmojis.Count() > 0)
// sb.AppendLine($"`Custom Emojis:` **{string.Join(", ", server.CustomEmojis)}**");
// if (server.Features.Count() > 0)
// sb.AppendLine($"`Features:` **{string.Join(", ", server.Features)}**");
// if (!string.IsNullOrWhiteSpace(server.SplashId))
// sb.AppendLine($"`Region:` **{server.Region.Name}**");
// await e.Channel.SendMessage(sb.ToString()).ConfigureAwait(false);
// });
// cgb.CreateCommand(Module.Prefix + "channelinfo")
// .Alias(Module.Prefix + "cinfo")
// .Description($"Shows info about the channel. If no channel is supplied, it defaults to current one. |`{Module.Prefix}cinfo #some-channel`")
// .Parameter("channel", ParameterType.Optional)
// .Do(async e =>
// {
// var chText = e.GetArg("channel")?.Trim();
// var ch = string.IsNullOrWhiteSpace(chText)
// ? e.Channel
// : e.Server.FindChannels(chText, Discord.ChannelType.Text).FirstOrDefault();
// if (ch == null)
// return;
// var createdAt = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(ch.Id >> 22);
// var sb = new StringBuilder();
// sb.AppendLine($"`Name:` **#{ch.Name}**");
// sb.AppendLine($"`Id:` **{ch.Id}**");
// sb.AppendLine($"`Created At:` **{createdAt}**");
// sb.AppendLine($"`Topic:` **{ch.Topic}**");
// sb.AppendLine($"`Users:` **{ch.Users.Count()}**");
// await e.Channel.SendMessage(sb.ToString()).ConfigureAwait(false);
// });
// cgb.CreateCommand(Module.Prefix + "userinfo")
// .Alias(Module.Prefix + "uinfo")
// .Description($"Shows info about the user. If no user is supplied, it defaults a user running the command. |`{Module.Prefix}uinfo @SomeUser`")
// .Parameter("user", ParameterType.Optional)
// .Do(async e =>
// {
// var userText = e.GetArg("user")?.Trim();
// var user = string.IsNullOrWhiteSpace(userText)
// ? e.User
// : e.Server.FindUsers(userText).FirstOrDefault();
// if (user == null)
// return;
// var sb = new StringBuilder();
// sb.AppendLine($"`Name#Discrim:` **#{user.Name}#{user.Discriminator}**");
// if (!string.IsNullOrWhiteSpace(user.Nickname))
// sb.AppendLine($"`Nickname:` **{user.Nickname}**");
// sb.AppendLine($"`Id:` **{user.Id}**");
// sb.AppendLine($"`Current Game:` **{(user.CurrentGame?.Name == null ? "-" : user.CurrentGame.Value.Name)}**");
// if (user.LastOnlineAt != null)
// sb.AppendLine($"`Last Online:` **{user.LastOnlineAt:HH:mm:ss}**");
// sb.AppendLine($"`Joined At:` **{user.JoinedAt}**");
// sb.AppendLine($"`Roles:` **({user.Roles.Count()}) - {string.Join(", ", user.Roles.Select(r => r.Name))}**");
// sb.AppendLine($"`AvatarUrl:` **{await user.AvatarUrl.ShortenUrl().ConfigureAwait(false)}**");
// await e.Channel.SendMessage(sb.ToString()).ConfigureAwait(false);
// });
// }
// }
//}

View File

@@ -0,0 +1,197 @@
//using Discord;
//using Discord.Commands;
//using NadekoBot.Classes;
//using NadekoBot.DataModels;
//using NadekoBot.Modules.Permissions.Classes;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text.RegularExpressions;
//using System.Timers;
//namespace NadekoBot.Modules.Utility.Commands
//{
// class Remind : DiscordCommand
// {
// Regex regex = new Regex(@"^(?:(?<months>\d)mo)?(?:(?<weeks>\d)w)?(?:(?<days>\d{1,2})d)?(?:(?<hours>\d{1,2})h)?(?:(?<minutes>\d{1,2})m)?$",
// RegexOptions.Compiled | RegexOptions.Multiline);
// List<Timer> reminders = new List<Timer>();
// IDictionary<string, Func<Reminder, string>> replacements = new Dictionary<string, Func<Reminder, string>>
// {
// { "%message%" , (r) => r.Message },
// { "%user%", (r) => $"<@!{r.UserId}>" },
// { "%target%", (r) => r.IsPrivate ? "Direct Message" : $"<#{r.ChannelId}>"}
// };
// public Remind(DiscordModule module) : base(module)
// {
// var remList = DbHandler.Instance.GetAllRows<Reminder>();
// reminders = remList.Select(StartNewReminder).ToList();
// }
// private Timer StartNewReminder(Reminder r)
// {
// var now = DateTime.Now;
// var twoMins = new TimeSpan(0, 2, 0);
// TimeSpan time = (r.When - now) < twoMins
// ? twoMins //if the time is less than 2 minutes,
// : r.When - now; //it will send the message 2 minutes after start
// //To account for high bot startup times
// if (time.TotalMilliseconds > int.MaxValue)
// return null;
// var t = new Timer(time.TotalMilliseconds);
// t.Elapsed += async (s, e) =>
// {
// try
// {
// Channel ch;
// if (r.IsPrivate)
// {
// ch = NadekoBot.Client.PrivateChannels.FirstOrDefault(c => (long)c.Id == r.ChannelId);
// if (ch == null)
// ch = await NadekoBot.Client.CreatePrivateChannel((ulong)r.ChannelId).ConfigureAwait(false);
// }
// else
// ch = NadekoBot.Client.GetServer((ulong)r.ServerId)?.GetChannel((ulong)r.ChannelId);
// if (ch == null)
// return;
// await ch.SendMessage(
// replacements.Aggregate(NadekoBot.Config.RemindMessageFormat,
// (cur, replace) => cur.Replace(replace.Key, replace.Value(r)))
// ).ConfigureAwait(false); //it works trust me
// }
// catch (Exception ex)
// {
// Console.WriteLine($"Timer error! {ex}");
// }
// finally
// {
// DbHandler.Instance.Delete<Reminder>(r.Id.Value);
// t.Stop();
// t.Dispose();
// }
// };
// t.Start();
// return t;
// }
// internal override void Init(CommandGroupBuilder cgb)
// {
// cgb.CreateCommand(Module.Prefix + "remind")
// .Description("Sends a message to you or a channel after certain amount of time. " +
// "First argument is me/here/'channelname'. Second argument is time in a descending order (mo>w>d>h>m) example: 1w5d3h10m. " +
// "Third argument is a (multiword)message. " +
// $" | `{Prefix}remind me 1d5h Do something` or `{Prefix}remind #general Start now!`")
// .Parameter("meorchannel", ParameterType.Required)
// .Parameter("time", ParameterType.Required)
// .Parameter("message", ParameterType.Unparsed)
// .Do(async e =>
// {
// var meorchStr = e.GetArg("meorchannel").ToUpperInvariant();
// Channel ch;
// bool isPrivate = false;
// if (meorchStr == "ME")
// {
// isPrivate = true;
// ch = await e.User.CreatePMChannel().ConfigureAwait(false);
// }
// else if (meorchStr == "HERE")
// {
// ch = e.Channel;
// }
// else
// {
// ch = e.Server.FindChannels(meorchStr).FirstOrDefault();
// }
// if (ch == null)
// {
// await e.Channel.SendMessage($"{e.User.Mention} Something went wrong (channel cannot be found) ;(").ConfigureAwait(false);
// return;
// }
// var timeStr = e.GetArg("time");
// var m = regex.Match(timeStr);
// if (m.Length == 0)
// {
// await e.Channel.SendMessage("Not a valid time format blablabla").ConfigureAwait(false);
// return;
// }
// string output = "";
// var namesAndValues = new Dictionary<string, int>();
// foreach (var groupName in regex.GetGroupNames())
// {
// if (groupName == "0") continue;
// int value = 0;
// int.TryParse(m.Groups[groupName].Value, out value);
// if (string.IsNullOrEmpty(m.Groups[groupName].Value))
// {
// namesAndValues[groupName] = 0;
// continue;
// }
// else if (value < 1 ||
// (groupName == "months" && value > 1) ||
// (groupName == "weeks" && value > 4) ||
// (groupName == "days" && value >= 7) ||
// (groupName == "hours" && value > 23) ||
// (groupName == "minutes" && value > 59))
// {
// await e.Channel.SendMessage($"Invalid {groupName} value.").ConfigureAwait(false);
// return;
// }
// else
// namesAndValues[groupName] = value;
// output += m.Groups[groupName].Value + " " + groupName + " ";
// }
// var time = DateTime.Now + new TimeSpan(30 * namesAndValues["months"] +
// 7 * namesAndValues["weeks"] +
// namesAndValues["days"],
// namesAndValues["hours"],
// namesAndValues["minutes"],
// 0);
// var rem = new Reminder
// {
// ChannelId = (long)ch.Id,
// IsPrivate = isPrivate,
// When = time,
// Message = e.GetArg("message"),
// UserId = (long)e.User.Id,
// ServerId = (long)e.Server.Id
// };
// DbHandler.Instance.Connection.Insert(rem);
// reminders.Add(StartNewReminder(rem));
// await e.Channel.SendMessage($"⏰ I will remind \"{ch.Name}\" to \"{e.GetArg("message").ToString()}\" in {output}. ({time:d.M.yyyy.} at {time:HH:mm})").ConfigureAwait(false);
// });
// cgb.CreateCommand(Module.Prefix + "remindmsg")
// .Description("Sets message for when the remind is triggered. " +
// " Available placeholders are %user% - user who ran the command, %message% -" +
// $" Message specified in the remind, %target% - target channel of the remind. **Bot Owner Only!** | `{Prefix}remindmsg do something else`")
// .Parameter("msg", ParameterType.Unparsed)
// .AddCheck(SimpleCheckers.OwnerOnly())
// .Do(async e =>
// {
// var arg = e.GetArg("msg")?.Trim();
// if (string.IsNullOrWhiteSpace(arg))
// return;
// NadekoBot.Config.RemindMessageFormat = arg;
// await e.Channel.SendMessage("`New remind message set.`");
// });
// }
// }
//}

View File

@@ -0,0 +1,175 @@
using Discord;
using Discord.Commands;
using NadekoBot.Attributes;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace NadekoBot.Modules.Utility
{
[Module(".", AppendSpace = false)]
public class UtilityModule
{
[LocalizedCommand]
[LocalizedDescription]
[LocalizedSummary]
[RequireContext(ContextType.Guild)]
public async Task WhoPlays(IMessage imsg, [Remainder] string game)
{
var chnl = (IGuildChannel)imsg.Channel;
game = game.Trim().ToUpperInvariant();
if (string.IsNullOrWhiteSpace(game))
return;
var arr = (await chnl.Guild.GetUsersAsync())
.Where(u => u.Game?.Name.ToUpperInvariant() == game)
.Select(u => u.Username)
.ToList();
int i = 0;
if (!arr.Any())
await imsg.Channel.SendMessageAsync("`Noone is playing that game.`").ConfigureAwait(false);
else
await imsg.Channel.SendMessageAsync("```xl\n" + string.Join("\n", arr.GroupBy(item => (i++) / 3).Select(ig => string.Concat(ig.Select(el => $"• {el,-35}")))) + "\n```").ConfigureAwait(false);
}
[LocalizedCommand]
[LocalizedDescription]
[LocalizedSummary]
[RequireContext(ContextType.Guild)]
public async Task InRole(IMessage imsg, [Remainder] string roles) {
if (string.IsNullOrWhiteSpace(roles))
return;
var channel = imsg.Channel as IGuildChannel;
var arg = roles.Split(',').Select(r => r.Trim().ToUpperInvariant());
string send = $"`Here is a list of users in a specfic role:`";
foreach (var roleStr in arg.Where(str => !string.IsNullOrWhiteSpace(str) && str != "@EVERYONE" && str != "EVERYONE"))
{
var role = channel.Guild.Roles.Where(r => r.Name.ToUpperInvariant() == roleStr).FirstOrDefault();
if (role == null) continue;
send += $"\n`{role.Name}`\n";
send += string.Join(", ", (await channel.Guild.GetUsersAsync()).Where(u=>u.Roles.Contains(role)).Select(u => u.ToString()));
}
//todo
//while (send.Length > 2000)
//{
// if (!)
// {
// await e.Channel.SendMessage($"{e.User.Mention} you are not allowed to use this command on roles with a lot of users in them to prevent abuse.");
// return;
// }
// var curstr = send.Substring(0, 2000);
// await imsg.Channel.SendMessageAsync(curstr.Substring(0,
// curstr.LastIndexOf(", ", StringComparison.Ordinal) + 1)).ConfigureAwait(false);
// send = curstr.Substring(curstr.LastIndexOf(", ", StringComparison.Ordinal) + 1) +
// send.Substring(2000);
//}
//await e.Channel.Send(send).ConfigureAwait(false);
}
}
}
//public void Install()
//{
// manager.CreateCommands("", cgb =>
// {
// cgb.AddCheck(PermissionChecker.Instance);
// var client = manager.Client;
// commands.ForEach(cmd => cmd.Init(cgb));
// cgb.CreateCommand(Prefix + "whoplays")
// .Description()
// .Parameter("game", ParameterType.Unparsed)
// .Do(async e =>
// {
// });
// cgb.CreateCommand(Prefix + "checkmyperms")
// .Description($"Checks your userspecific permissions on this channel. | `{Prefix}checkmyperms`")
// .Do(async e =>
// {
// var output = "```\n";
// foreach (var p in e.User.ServerPermissions.GetType().GetProperties().Where(p => !p.GetGetMethod().GetParameters().Any()))
// {
// output += p.Name + ": " + p.GetValue(e.User.ServerPermissions, null).ToString() + "\n";
// }
// output += "```";
// await e.User.SendMessage(output).ConfigureAwait(false);
// });
// cgb.CreateCommand(Prefix + "stats")
// .Description($"Shows some basic stats for Nadeko. | `{Prefix}stats`")
// .Do(async e =>
// {
// await e.Channel.SendMessage(await NadekoStats.Instance.GetStats()).ConfigureAwait(false);
// });
// cgb.CreateCommand(Prefix + "dysyd")
// .Description($"Shows some basic stats for Nadeko. | `{Prefix}dysyd`")
// .Do(async e =>
// {
// await e.Channel.SendMessage((await NadekoStats.Instance.GetStats()).Matrix().TrimTo(1990)).ConfigureAwait(false);
// });
// cgb.CreateCommand(Prefix + "userid").Alias(Prefix + "uid")
// .Description($"Shows user ID. | `{Prefix}uid` or `{Prefix}uid \"@SomeGuy\"`")
// .Parameter("user", ParameterType.Unparsed)
// .Do(async e =>
// {
// var usr = e.User;
// if (!string.IsNullOrWhiteSpace(e.GetArg("user"))) usr = e.Channel.FindUsers(e.GetArg("user")).FirstOrDefault();
// if (usr == null)
// return;
// await e.Channel.SendMessage($"Id of the user { usr.Name } is { usr.Id }").ConfigureAwait(false);
// });
// cgb.CreateCommand(Prefix + "channelid").Alias(Prefix + "cid")
// .Description($"Shows current channel ID. | `{Prefix}cid`")
// .Do(async e => await e.Channel.SendMessage("This channel's ID is " + e.Channel.Id).ConfigureAwait(false));
// cgb.CreateCommand(Prefix + "serverid").Alias(Prefix + "sid")
// .Description($"Shows current server ID. | `{Prefix}sid`")
// .Do(async e => await e.Channel.SendMessage("This server's ID is " + e.Server.Id).ConfigureAwait(false));
// cgb.CreateCommand(Prefix + "roles")
// .Description("List all roles on this server or a single user if specified. | `{Prefix}roles`")
// .Parameter("user", ParameterType.Unparsed)
// .Do(async e =>
// {
// if (!string.IsNullOrWhiteSpace(e.GetArg("user")))
// {
// var usr = e.Server.FindUsers(e.GetArg("user")).FirstOrDefault();
// if (usr == null) return;
// await e.Channel.SendMessage($"`List of roles for **{usr.Name}**:` \n• " + string.Join("\n• ", usr.Roles)).ConfigureAwait(false);
// return;
// }
// await e.Channel.SendMessage("`List of roles:` \n• " + string.Join("\n• ", e.Server.Roles)).ConfigureAwait(false);
// });
// cgb.CreateCommand(Prefix + "channeltopic")
// .Alias(Prefix + "ct")
// .Description($"Sends current channel's topic as a message. | `{Prefix}ct`")
// .Do(async e =>
// {
// var topic = e.Channel.Topic;
// if (string.IsNullOrWhiteSpace(topic))
// return;
// await e.Channel.SendMessage(topic).ConfigureAwait(false);
// });
// });
// }
// }
//}