Merge pull request #342 from Kwoth/dev

0.99 Update
This commit is contained in:
Master Kwoth 2016-06-15 13:43:34 +02:00 committed by GitHub
commit a9299f842d
12 changed files with 83 additions and 75 deletions

View File

@ -30,12 +30,14 @@ namespace NadekoBot.Modules.Administration
commands.Add(new InfoCommands(this)); commands.Add(new InfoCommands(this));
commands.Add(new CustomReactionsCommands(this)); commands.Add(new CustomReactionsCommands(this));
commands.Add(new AutoAssignRole(this)); commands.Add(new AutoAssignRole(this));
commands.Add(new SelfCommands(this));
} }
public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Administration; public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Administration;
public override void Install(ModuleManager manager) public override void Install(ModuleManager manager)
{ {
manager.CreateCommands("", cgb => manager.CreateCommands("", cgb =>
{ {
@ -720,11 +722,13 @@ namespace NadekoBot.Modules.Administration
var avatarAddress = e.GetArg("img"); var avatarAddress = e.GetArg("img");
var imageStream = await SearchHelper.GetResponseStreamAsync(avatarAddress).ConfigureAwait(false); var imageStream = await SearchHelper.GetResponseStreamAsync(avatarAddress).ConfigureAwait(false);
var image = System.Drawing.Image.FromStream(imageStream); var image = System.Drawing.Image.FromStream(imageStream);
// Save the image to disk.
image.Save("data/avatar.png", System.Drawing.Imaging.ImageFormat.Png);
await client.CurrentUser.Edit(NadekoBot.Creds.Password, avatar: image.ToStream()).ConfigureAwait(false); await client.CurrentUser.Edit(NadekoBot.Creds.Password, avatar: image.ToStream()).ConfigureAwait(false);
// Send confirm. // Send confirm.
await e.Channel.SendMessage("New avatar set.").ConfigureAwait(false); await e.Channel.SendMessage("New avatar set.").ConfigureAwait(false);
// Save the image to disk.
image.Save("data/avatar.png", System.Drawing.Imaging.ImageFormat.Png);
}); });
cgb.CreateCommand(Prefix + "setgame") cgb.CreateCommand(Prefix + "setgame")
@ -998,6 +1002,21 @@ namespace NadekoBot.Modules.Administration
await e.Channel.SendMessage("```xl\n" + string.Join("\n", arr.GroupBy(item => (i++) / 3).Select(ig => string.Join("", ig.Select(el => $"• {el,-35}")))) + "\n```"); await e.Channel.SendMessage("```xl\n" + string.Join("\n", arr.GroupBy(item => (i++) / 3).Select(ig => string.Join("", ig.Select(el => $"• {el,-35}")))) + "\n```");
}); });
cgb.CreateCommand(Prefix + "leave")
.Description("Leaves a server with a supplied ID.\n**Usage**: `.leave 493243292839`")
.Parameter("num", ParameterType.Required)
.AddCheck(SimpleCheckers.OwnerOnly())
.Do(async e =>
{
var srvr = NadekoBot.Client.Servers.Where(s => s.Id.ToString() == e.GetArg("num").Trim()).FirstOrDefault();
if (srvr == null)
{
return;
}
await srvr.Leave();
await e.Channel.SendMessage("`Done.`");
});
}); });
} }

View File

@ -32,8 +32,8 @@ namespace NadekoBot.Modules.Administration.Commands
internal override void Init(CommandGroupBuilder cgb) internal override void Init(CommandGroupBuilder cgb)
{ {
cgb.CreateCommand(Module.Prefix + "aar") cgb.CreateCommand(Module.Prefix + "autoassignrole")
.Alias(Module.Prefix + "autoassignrole") .Alias(Module.Prefix + "aar")
.Description($"Automaticaly assigns a specified role to every user who joins the server. Type `.aar` to disable, `.aar Role Name` to enable") .Description($"Automaticaly assigns a specified role to every user who joins the server. Type `.aar` to disable, `.aar Role Name` to enable")
.Parameter("role", ParameterType.Unparsed) .Parameter("role", ParameterType.Unparsed)
.AddCheck(new SimpleCheckers.ManageRoles()) .AddCheck(new SimpleCheckers.ManageRoles())
@ -42,6 +42,7 @@ namespace NadekoBot.Modules.Administration.Commands
if (!e.Server.CurrentUser.ServerPermissions.ManageRoles) if (!e.Server.CurrentUser.ServerPermissions.ManageRoles)
{ {
await e.Channel.SendMessage("I do not have the permission to manage roles."); await e.Channel.SendMessage("I do not have the permission to manage roles.");
return;
} }
var r = e.GetArg("role")?.Trim(); var r = e.GetArg("role")?.Trim();

View File

@ -67,7 +67,7 @@ namespace NadekoBot.Modules.Administration.Commands
}); });
cgb.CreateCommand(Module.Prefix + "lsar") cgb.CreateCommand(Module.Prefix + "lsar")
.Description("Lits all self-assignable roles.") .Description("Lists all self-assignable roles.")
.Parameter("roles", ParameterType.Multiple) .Parameter("roles", ParameterType.Multiple)
.Do(async e => .Do(async e =>
{ {

View File

@ -0,0 +1,46 @@
using NadekoBot.Classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Discord.Commands;
using NadekoBot.Modules.Permissions.Classes;
namespace NadekoBot.Modules.Administration.Commands
{
class SelfCommands : DiscordCommand
{
public SelfCommands(DiscordModule module) : base(module)
{
}
internal override void Init(CommandGroupBuilder cgb)
{
cgb.CreateCommand(Module.Prefix + "leave")
.Description("Makes Nadeko leave the server. Either name or id required.\n**Usage**:.leave NSFW")
.Parameter("arg", ParameterType.Required)
.AddCheck(SimpleCheckers.OwnerOnly())
.Do(async e =>
{
var arg = e.GetArg("arg")?.Trim();
var server = NadekoBot.Client.Servers.FirstOrDefault(s => s.Id.ToString() == arg) ??
NadekoBot.Client.FindServers(arg.Trim()).FirstOrDefault();
if (server == null)
{
await e.Channel.SendMessage("Cannot find that server").ConfigureAwait(false);
return;
}
if (!server.IsOwner)
{
await server.Leave();
}
else
{
await server.Delete();
}
await NadekoBot.SendMessageToOwner("Left server " + server.Name);
});
}
}
}

View File

@ -258,28 +258,6 @@ namespace NadekoBot.Modules.Conversations
await e.Channel.SendMessage("I can't find a message mentioning you.").ConfigureAwait(false); await e.Channel.SendMessage("I can't find a message mentioning you.").ConfigureAwait(false);
}); });
cgb.CreateCommand("hide")
.Description("Hides Nadeko in plain sight!11!!")
.Do(async e =>
{
using (var ms = Resources.hidden.ToStream(ImageFormat.Png))
{
await client.CurrentUser.Edit(NadekoBot.Creds.Password, avatar: ms).ConfigureAwait(false);
}
await e.Channel.SendMessage("*hides*").ConfigureAwait(false);
});
cgb.CreateCommand("unhide")
.Description("Unhides Nadeko in plain sight!1!!1")
.Do(async e =>
{
using (var fs = new FileStream("data/avatar.png", FileMode.Open))
{
await client.CurrentUser.Edit(NadekoBot.Creds.Password, avatar: fs).ConfigureAwait(false);
}
await e.Channel.SendMessage("*unhides*").ConfigureAwait(false);
});
cgb.CreateCommand("dump") cgb.CreateCommand("dump")
.Description("Dumps all of the invites it can to dump.txt.** Owner Only.**") .Description("Dumps all of the invites it can to dump.txt.** Owner Only.**")
.Do(async e => .Do(async e =>

View File

@ -94,7 +94,7 @@ namespace NadekoBot.Modules.Gambling
}); });
cgb.CreateCommand(Prefix + "award") cgb.CreateCommand(Prefix + "award")
.Description("Gives someone a certain amount of flowers. **Owner only!**") .Description("Gives someone a certain amount of flowers. **Owner only!**\n**Usage**: `$award 100 @person`")
.AddCheck(SimpleCheckers.OwnerOnly()) .AddCheck(SimpleCheckers.OwnerOnly())
.Parameter("amount", ParameterType.Required) .Parameter("amount", ParameterType.Required)
.Parameter("receiver", ParameterType.Unparsed) .Parameter("receiver", ParameterType.Unparsed)

View File

@ -2,7 +2,6 @@
using Discord.Commands; using Discord.Commands;
using NadekoBot.Classes; using NadekoBot.Classes;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -79,10 +78,7 @@ namespace NadekoBot.Modules.Games.Commands.Trivia
await Task.Delay(QuestionDurationMiliseconds - HintTimeoutMiliseconds, token).ConfigureAwait(false); await Task.Delay(QuestionDurationMiliseconds - HintTimeoutMiliseconds, token).ConfigureAwait(false);
} }
catch (TaskCanceledException) catch (TaskCanceledException) { } //means someone guessed the answer
{
Console.WriteLine("Trivia cancelled");
}
GameActive = false; GameActive = false;
if (!triviaCancelSource.IsCancellationRequested) if (!triviaCancelSource.IsCancellationRequested)
await channel.Send($":clock2: :question: **Time's up!** The correct answer was **{CurrentQuestion.Answer}**").ConfigureAwait(false); await channel.Send($":clock2: :question: **Time's up!** The correct answer was **{CurrentQuestion.Answer}**").ConfigureAwait(false);

View File

@ -63,30 +63,12 @@ namespace NadekoBot.Modules.Trello
} }
}; };
manager.CreateCommands("trello ", cgb => manager.CreateCommands("", cgb =>
{ {
cgb.AddCheck(PermissionChecker.Instance); cgb.AddCheck(PermissionChecker.Instance);
cgb.CreateCommand("join") cgb.CreateCommand(Prefix + "bind")
.Alias("j")
.Description("Joins a server")
.Parameter("code", Discord.Commands.ParameterType.Required)
.Do(async e =>
{
if (!NadekoBot.IsOwner(e.User.Id) || NadekoBot.IsBot) return;
try
{
await (await client.GetInvite(e.GetArg("code")).ConfigureAwait(false)).Accept()
.ConfigureAwait(false);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
});
cgb.CreateCommand("bind")
.Description("Bind a trello bot to a single channel. " + .Description("Bind a trello bot to a single channel. " +
"You will receive notifications from your board when something is added or edited." + "You will receive notifications from your board when something is added or edited." +
"\n**Usage**: bind [board_id]") "\n**Usage**: bind [board_id]")
@ -109,7 +91,7 @@ namespace NadekoBot.Modules.Trello
} }
}); });
cgb.CreateCommand("unbind") cgb.CreateCommand(Prefix + "unbind")
.Description("Unbinds a bot from the channel and board.") .Description("Unbinds a bot from the channel and board.")
.Do(async e => .Do(async e =>
{ {
@ -122,8 +104,8 @@ namespace NadekoBot.Modules.Trello
}); });
cgb.CreateCommand("lists") cgb.CreateCommand(Prefix + "lists")
.Alias("list") .Alias(Prefix + "list")
.Description("Lists all lists yo ;)") .Description("Lists all lists yo ;)")
.Do(async e => .Do(async e =>
{ {
@ -133,7 +115,7 @@ namespace NadekoBot.Modules.Trello
.ConfigureAwait(false); .ConfigureAwait(false);
}); });
cgb.CreateCommand("cards") cgb.CreateCommand(Prefix + "cards")
.Description("Lists all cards from the supplied list. You can supply either a name or an index.") .Description("Lists all cards from the supplied list. You can supply either a name or an index.")
.Parameter("list_name", Discord.Commands.ParameterType.Unparsed) .Parameter("list_name", Discord.Commands.ParameterType.Unparsed)
.Do(async e => .Do(async e =>

View File

@ -48,21 +48,6 @@ namespace NadekoBot
{ {
Console.OutputEncoding = Encoding.Unicode; Console.OutputEncoding = Encoding.Unicode;
//var lines = File.ReadAllLines("data/input.txt");
//HashSet<dynamic> list = new HashSet<dynamic>();
//for (int i = 0; i < lines.Length; i += 3) {
// dynamic obj = new JArray();
// obj.Text = lines[i];
// obj.Author = lines[i + 1];
// if (obj.Author.StartsWith("-"))
// obj.Author = obj.Author.Substring(1, obj.Author.Length - 1).Trim();
// list.Add(obj);
//}
//File.WriteAllText("data/quotes.json", Newtonsoft.Json.JsonConvert.SerializeObject(list, Formatting.Indented));
//Console.ReadKey();
// generate credentials example so people can know about the changes i make
try try
{ {
File.WriteAllText("data/config_example.json", JsonConvert.SerializeObject(new Configuration(), Formatting.Indented)); File.WriteAllText("data/config_example.json", JsonConvert.SerializeObject(new Configuration(), Formatting.Indented));
@ -252,7 +237,7 @@ namespace NadekoBot
public static bool IsOwner(ulong id) => Creds.OwnerIds.Contains(id); public static bool IsOwner(ulong id) => Creds.OwnerIds.Contains(id);
public async Task SendMessageToOwner(string message) public static async Task SendMessageToOwner(string message)
{ {
if (Config.ForwardMessages && OwnerPrivateChannel != null) if (Config.ForwardMessages && OwnerPrivateChannel != null)
await OwnerPrivateChannel.SendMessage(message).ConfigureAwait(false); await OwnerPrivateChannel.SendMessage(message).ConfigureAwait(false);

View File

@ -136,6 +136,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Modules\Administration\Commands\AutoAssignRole.cs" /> <Compile Include="Modules\Administration\Commands\AutoAssignRole.cs" />
<Compile Include="Modules\Administration\Commands\CustomReactionsCommands.cs" /> <Compile Include="Modules\Administration\Commands\CustomReactionsCommands.cs" />
<Compile Include="Modules\Administration\Commands\SelfCommands.cs" />
<Compile Include="Modules\ClashOfClans\ClashOfClans.cs" /> <Compile Include="Modules\ClashOfClans\ClashOfClans.cs" />
<Compile Include="Classes\DBHandler.cs" /> <Compile Include="Classes\DBHandler.cs" />
<Compile Include="Classes\FlowersHandler.cs" /> <Compile Include="Classes\FlowersHandler.cs" />