void IModule.Install(ModuleManager manager) { _manager = manager; _client = manager.Client; _http = _client.Services.Get<HttpService>(); _settings = _client.Services.Get<SettingsService>() .AddModule<StatusModule, Settings>(manager); manager.CreateCommands("status", group => { group.MinPermissions((int)PermissionLevel.BotOwner); group.CreateCommand("enable") .Parameter("channel", ParameterType.Optional) .Do(async e => { var settings = _settings.Load(e.Server); Channel channel; if (e.Args[0] != "") channel = await _client.FindChannel(e, e.Args[0], ChannelType.Text); else channel = e.Channel; if (channel == null) return; settings.Channel = channel.Id; await _settings.Save(e.Server, settings); await _client.Reply(e, $"Enabled status reports in {channel.Name}"); }); group.CreateCommand("disable") .Do(async e => { var settings = _settings.Load(e.Server); settings.Channel = null; await _settings.Save(e.Server, settings); await _client.Reply(e, "Disabled status reports on this server."); }); }); _client.LoggedIn += (s, e) => { if (!_isRunning) { Task.Run(Run); _isRunning = true; } }; }
void IModule.Install(ModuleManager manager) { _manager = manager; _client = _manager.Client; manager.CreateCommands("colors", group => { //group.SetAlias("colours"); //TODO: add group alias and absolute vs relative alias group.CreateCommand("list") .Description("Gives a list of all available username colors.") .Do(async e => { string text = $"{Format.Bold("Available Colors:")}\n" + string.Join(", ", _colors.Select(x => '`' + x.Name + '`')); await _client.Reply(e, text); }); group.CreateCommand("set") .Parameter("color") .Description("Sets your username to a custom color.") .Do(e => SetColor(e, e.User, e.Args[0])); group.CreateCommand("set") .Parameter("user") .Parameter("color") .MinPermissions((int)PermissionLevel.BotOwner) .Description("Sets another user's name to a custom color.") .Do(e => { User user = e.Server.FindUsers(e.Args[0]).FirstOrDefault(); if (user == null) return _client.ReplyError(e, "Unknown user"); return SetColor(e, user, e.Args[1]); }); group.CreateCommand("clear") .Description("Removes your username color, returning it to default.") .Do(async e => { if (!e.Server.CurrentUser.ServerPermissions.ManageRoles) { await _client.ReplyError(e, "This command requires the bot have Manage Roles permission."); return; } var otherRoles = GetOtherRoles(e.User); await e.User.Edit(roles: otherRoles); await _client.Reply(e, $"Reset username color."); }); }); }
void IModule.Install(ModuleManager manager) { _manager = manager; _client = manager.Client; _service = manager.Client.Modules(true); manager.CreateCommands("modules", group => { group.MinPermissions((int)PermissionLevel.BotOwner); group.CreateCommand("list") .Description("Gives a list of all available modules.") .Do(async e => { string text = "Available Modules: " + string.Join(", ", _service.Modules.Select(x => x.Id)); await _client.Reply(e, text); }); group.CreateCommand("enable") .Description("Enables a module for this server.") .Parameter("module") .PublicOnly() .Do(e => { var module = GetModule(e.Args[0]); if (module == null) { _client.ReplyError(e, "Unknown module"); return; } if (module.FilterType == ModuleFilter.None || module.FilterType == ModuleFilter.AlwaysAllowPrivate) { _client.ReplyError(e, "This module is global and cannot be enabled/disabled."); return; } if (!module.FilterType.HasFlag(ModuleFilter.ServerWhitelist)) { _client.ReplyError(e, "This module doesn't support being enabled for servers."); return; } var server = e.Server; if (!module.EnableServer(server)) { _client.ReplyError(e, $"Module {module.Id} was already enabled for server {server.Name}."); return; } _client.Reply(e, $"Module {module.Id} was enabled for server {server.Name}."); }); group.CreateCommand("disable") .Description("Disables a module for this server.") .Parameter("module") .PublicOnly() .Do(e => { var module = GetModule(e.Args[0]); if (module == null) { _client.ReplyError(e, "Unknown module"); return; } if (module.FilterType == ModuleFilter.None || module.FilterType == ModuleFilter.AlwaysAllowPrivate) { _client.ReplyError(e, "This module is global and cannot be enabled/disabled."); return; } if (!module.FilterType.HasFlag(ModuleFilter.ServerWhitelist)) { _client.ReplyError(e, "This module doesn't support being enabled for servers."); return; } var server = e.Server; if (!module.DisableServer(server)) { _client.ReplyError(e, $"Module {module.Id} was not enabled for server {server.Name}."); return; } _client.Reply(e, $"Module {module.Id} was disabled for server {server.Name}."); }); }); }
void IModule.Install(ModuleManager manager) { _manager = manager; _client = manager.Client; _http = _client.Services.Get<HttpService>(); _settings = _client.Services.Get<SettingsService>() .AddModule<TwitchModule, Settings>(manager); manager.CreateCommands("streams", group => { group.MinPermissions((int)PermissionLevel.BotOwner); group.CreateCommand("list") .Do(async e => { StringBuilder builder = new StringBuilder(); var settings = _settings.Load(e.Server); foreach (var channel in settings.Channels) builder.AppendLine($"{_client.GetChannel(channel.Key)}:\n {string.Join(", ", channel.Value.Streams.Select(x => x.Key))}"); await _client.Reply(e, "Linked Streams", builder.ToString()); }); group.CreateCommand("add") .Parameter("twitchuser") .Parameter("channel", ParameterType.Optional) .Do(async e => { var settings = _settings.Load(e.Server); Channel channel; if (e.Args[1] != "") channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text); else channel = e.Channel; if (channel == null) return; var channelSettings = settings.GetOrAddChannel(channel.Id); if (channelSettings.AddStream(e.Args[0])) { await _settings.Save(e.Server, settings); await _client.Reply(e, $"Linked stream {e.Args[0]} to {channel.Name}."); } else await _client.Reply(e, $"Stream {e.Args[0]} is already linked to {channel.Name}."); }); group.CreateCommand("remove") .Parameter("twitchuser") .Parameter("channel", ParameterType.Optional) .Do(async e => { var settings = _settings.Load(e.Server); Channel channel; if (e.Args[1] != "") channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text); else channel = e.Channel; if (channel == null) return; var channelSettings = settings.GetOrAddChannel(channel.Id); if (channelSettings.RemoveStream(e.Args[0])) { await _settings.Save(e.Server.Id, settings); await _client.Reply(e, $"Unlinked stream {e.Args[0]} from {channel.Name}."); } else await _client.Reply(e, $"Stream {e.Args[0]} is not currently linked to {channel.Name}."); }); group.CreateGroup("set", set => { set.CreateCommand("sticky") .Parameter("value") .Parameter("channel", ParameterType.Optional) .Do(async e => { bool value = false; bool.TryParse(e.Args[0], out value); Channel channel; if (e.Args[1] != "") channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text); else channel = e.Channel; if (channel == null) return; var settings = _settings.Load(e.Server); var channelSettings = settings.GetOrAddChannel(channel.Id); if (channelSettings.UseSticky && !value && channelSettings.StickyMessageId != null) { var msg = channel.GetMessage(channelSettings.StickyMessageId.Value); try { await msg.Delete(); } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { } } channelSettings.UseSticky = value; await _settings.Save(e.Server, settings); await _client.Reply(e, $"Stream sticky for {channel.Name} set to {value}."); }); }); }); _client.Connected += (s, e) => { if (!_isRunning) { Task.Run(Run); _isRunning = true; } }; }
void IModule.Install(ModuleManager manager) { _manager = manager; _client = manager.Client; _http = _client.Services.Get<HttpService>(); _settings = _client.Services.Get<SettingsService>() .AddModule<GithubModule, Settings>(manager); manager.CreateCommands("repos", group => { group.MinPermissions((int)PermissionLevel.BotOwner); group.CreateCommand("list") .Do(async e => { StringBuilder builder = new StringBuilder(); var settings = _settings.Load(e.Server); foreach (var repo in settings.Repos.OrderBy(x => x.Key)) builder.AppendLine($"{repo.Key} [{string.Join(",", repo.Value.Branches)}] => {_client.GetChannel(repo.Value.ChannelId)?.Name ?? "Unknown"}"); await _client.Reply(e, "Linked Repos", builder.ToString()); }); group.CreateCommand("add") .Parameter("githubrepo") .Parameter("channel", ParameterType.Optional) .Do(async e => { var settings = _settings.Load(e.Server); Channel channel; if (e.Args[1] != "") channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text); else channel = e.Channel; if (channel == null) return; string url = FilterUrl(e.Args[0]); if (settings.AddRepo(url, channel.Id)) { await _settings.Save(e.Server.Id, settings); await _client.Reply(e, $"Linked repo {url} to {channel.Name}."); } else await _client.Reply(e, $"Error: Repo {url} is already being watched."); }); group.CreateCommand("remove") .Parameter("githubrepo") .Do(async e => { var settings = _settings.Load(e.Server); string url = FilterUrl(e.Args[0]); if (settings.RemoveRepo(url)) { await _settings.Save(e.Server.Id, settings); await _client.Reply(e, $"Unlinked repo {url}."); } else await _client.Reply(e, $"Error: Repo {url} is not currently being watched."); }); group.CreateCommand("addbranch") .Parameter("githubrepo") .Parameter("branch") .Do(async e => { var settings = _settings.Load(e.Server); string url = FilterUrl(e.Args[0]); var repo = settings.Repos[url]; if (repo != null) { if (repo.AddBranch(e.Args[1])) { await _settings.Save(e.Server.Id, settings); await _client.Reply(e, $"Added branch {url}/{e.Args[1]}."); } else await _client.Reply(e, $"Error: Branch {url}/{e.Args[1]} is already being watched."); } else await _client.Reply(e, $"Error: Repo {url} is not currently being watched."); }); group.CreateCommand("removebranch") .Parameter("githubrepo") .Parameter("branch") .Do(async e => { var settings = _settings.Load(e.Server); string url = FilterUrl(e.Args[0]); var repo = settings.Repos[url]; if (repo != null) { if (repo.RemoveBranch(e.Args[1])) { await _settings.Save(e.Server.Id, settings); await _client.Reply(e, $"Removed branch {url}/{e.Args[1]}."); } else await _client.Reply(e, $"Error: Branch {url}/{e.Args[1]} is not being watched."); } else await _client.Reply(e, $"Error: Repo {url} is not currently being watched."); }); }); _client.Connected += (s, e) => { if (!_isRunning) { Task.Run(Run); _isRunning = true; } }; }
void IModule.Install(ModuleManager manager) { _manager = manager; _client = manager.Client; _http = _client.Services.Get<HttpService>(); _settings = _client.Services.Get<SettingsService>() .AddModule<FeedModule, Settings>(manager); manager.CreateCommands("feeds", group => { group.MinPermissions((int)PermissionLevel.BotOwner); group.CreateCommand("list") .Do(async e => { var settings = _settings.Load(e.Server); var response = settings.Feeds .OrderBy(x => x.Key) .Select(x => $"{x.Key} => {_client.GetChannel(x.Value.ChannelId)?.Name ?? "Unknown"}"); await _client.Reply(e, "Linked Feeds", response); }); group.CreateCommand("add") .Parameter("url") .Parameter("channel", ParameterType.Optional) .Do(async e => { var settings = _settings.Load(e.Server); Channel channel; if (e.Args[1] != "") channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text); else channel = e.Channel; if (channel == null) return; if (settings.AddFeed(e.Args[0], channel.Id)) { await _settings.Save(e.Server, settings); await _client.Reply(e, $"Linked feed {e.Args[0]} to {channel.Name}"); } else await _client.Reply(e, $"Feed {e.Args[0]} is already linked to a channel."); }); group.CreateCommand("remove") .Parameter("url") .Do(async e => { var settings = _settings.Load(e.Server); if (settings.RemoveFeed(e.Args[0])) { await _settings.Save(e.Server, settings); await _client.Reply(e, $"Unlinked feed {e.Args[0]}."); } else await _client.Reply(e, $"Feed {e.Args[0]} is not currently linked to a channel."); }); }); _client.Connected += (s, e) => { if (!_isRunning) { Task.Run(Run); _isRunning = true; } }; }
void IModule.Install(ModuleManager manager) { _manager = manager; _client = manager.Client; manager.CreateCommands("", group => { group.MinPermissions((int)PermissionLevel.User); group.CreateCommand("join") .Description("Requests the bot to join another server.") .Parameter("invite url") .MinPermissions((int)PermissionLevel.BotOwner) .Do(async e => { var invite = await _client.GetInvite(e.Args[0]); if (invite == null) { await _client.Reply(e, $"Invite not found."); return; } else if (invite.IsRevoked) { await _client.Reply(e, $"This invite has expired or the bot is banned from that server."); return; } await invite.Accept(); await _client.Reply(e, $"Joined server."); }); group.CreateCommand("leave") .Description("Instructs the bot to leave this server.") .MinPermissions((int)PermissionLevel.ServerModerator) .Do(async e => { await _client.Reply(e, $"Leaving~"); await e.Server.Leave(); }); group.CreateCommand("say") .Parameter("Text", ParameterType.Unparsed) .MinPermissions((int)PermissionLevel.BotOwner) .Do(async e => { await e.Channel.SendMessage(e.Message.Resolve(Format.Escape(e.Args[0]))); }); group.CreateCommand("sayraw") .Parameter("Text", ParameterType.Unparsed) .MinPermissions((int)PermissionLevel.BotOwner) .Do(async e => { await e.Channel.SendMessage(e.Args[0]); }); group.CreateCommand("info") .Alias("about") .MinPermissions((int)PermissionLevel.BotOwner) .Do(async e => { await e.Channel.SendMessage( $"{Format.Bold("Info")}\n" + $"- Author: Voltana (ID 53905483156684800)\n" + $"- Library: {DiscordConfig.LibName} ({DiscordConfig.LibVersion})\n" + $"- Runtime: {GetRuntime()} {GetBitness()}\n" + $"- Uptime: {GetUptime()}\n\n" + $"{Format.Bold("Stats")}\n" + $"- Heap Size: {GetHeapSize()} MB\n" + $"- Servers: {_client.Servers.Count()}\n" + $"- Channels: {_client.Servers.Sum(x => x.AllChannels.Count())}\n" + $"- Users: {_client.Servers.Sum(x => x.Users.Count())}" ); }); }); }
void IModule.Install(ModuleManager manager) { _manager = manager; _client = manager.Client; manager.CreateCommands("", group => { group.PublicOnly(); group.CreateCommand("kick") .Description("Kicks a user from this server.") .Parameter("user") .Parameter("discriminator", ParameterType.Optional) .MinPermissions((int)PermissionLevel.ServerModerator) .Do(async e => { var user = await _client.FindUser(e, e.Args[0], e.Args[1]); if (user == null) return; await user.Kick(); await _client.Reply(e, $"Kicked user {user.Name}."); }); group.CreateCommand("ban") .Description("Bans a user from this server.") .Parameter("user") .Parameter("discriminator", ParameterType.Optional) .MinPermissions((int)PermissionLevel.ServerModerator) .Do(async e => { var user = await _client.FindUser(e, e.Args[0], e.Args[1]); if (user == null) return; await user.Server.Ban(user); await _client.Reply(e, $"Banned user {user.Name}."); }); group.CreateCommand("mute") .Parameter("user") .Parameter("discriminator", ParameterType.Optional) .MinPermissions((int)PermissionLevel.ServerModerator) .Do(async e => { var user = await _client.FindUser(e, e.Args[0], e.Args[1]); if (user == null) return; await user.Edit(isMuted: true); await _client.Reply(e, $"Muted user {user.Name}."); }); group.CreateCommand("unmute") .Parameter("user") .Parameter("discriminator", ParameterType.Optional) .MinPermissions((int)PermissionLevel.ServerModerator) .Do(async e => { var user = await _client.FindUser(e, e.Args[0], e.Args[1]); if (user == null) return; await user.Edit(isMuted: false); await _client.Reply(e, $"Unmuted user {user.Name}."); }); group.CreateCommand("deafen") .Parameter("user") .Parameter("discriminator", ParameterType.Optional) .MinPermissions((int)PermissionLevel.ServerModerator) .Do(async e => { var user = await _client.FindUser(e, e.Args[0], e.Args[1]); if (user == null) return; await user.Edit(isDeafened: true); await _client.Reply(e, $"Deafened user {user.Name}."); }); group.CreateCommand("undeafen") .Parameter("user") .Parameter("discriminator", ParameterType.Optional) .MinPermissions((int)PermissionLevel.ServerModerator) .Do(async e => { var user = await _client.FindUser(e, e.Args[0], e.Args[1]); if (user == null) return; await user.Edit(isDeafened: false); await _client.Reply(e, $"Undeafened user {user.Name}."); }); group.CreateCommand("cleanup") .Parameter("count") .Parameter("user", ParameterType.Optional) .Parameter("discriminator", ParameterType.Optional) .MinPermissions((int)PermissionLevel.ChannelModerator) .Do(async e => { int count = int.Parse(e.Args[0]); string username = e.Args[1]; string discriminator = e.Args[2]; User[] users = null; if (username != "") { users = await _client.FindUsers(e, username, discriminator); if (users == null) return; } IEnumerable<Message> msgs; var cachedMsgs = e.Channel.Messages; if (cachedMsgs.Count() < count) msgs = (await e.Channel.DownloadMessages(count)); else msgs = e.Channel.Messages.OrderByDescending(x => x.Timestamp).Take(count); if (username != "") msgs = msgs.Where(x => users.Contains(x.User)); if (msgs.Any()) { foreach (var msg in msgs) await msg.Delete(); await _client.Reply(e, $"Cleaned up {msgs.Count()} messages."); } else await _client.ReplyError(e, $"No messages found."); }); }); }