Merge pull request #2 from Kwoth/1.0

1.0
This commit is contained in:
miraai 2016-11-08 21:33:38 +01:00 committed by GitHub
commit bc32531719
16 changed files with 610 additions and 179 deletions

View File

@ -1,17 +1,17 @@
For more information and how to setup your own NadekoBot, go to: <http://github.com/Kwoth/NadekoBot/wiki>
You can support the project on patreon: <https://patreon.com/nadekobot> or paypal: `nadekodiscordbot@gmail.com`
##Table Of Contents
- [Searches](#searches)
- [NSFW](#nsfw)
- [Music](#music)
- [Help](#help)
- [Permissions](#permissions)
- [Gambling](#gambling)
- [Administration](#administration)
- [Utility](#utility)
- [ClashOfClans](#clashofclans)
- [CustomReactions](#customreactions)
- [Gambling](#gambling)
- [Games](#games)
- [Music](#music)
- [NSFW](#nsfw)
- [Permissions](#permissions)
- [Searches](#searches)
- [Utility](#utility)
### Administration
@ -19,35 +19,35 @@ Command and aliases | Description | Usage
----------------|--------------|-------
`.resetperms` | Resets BOT's permissions module on this server to the default value. **Requires Administrator server permission.** | `.resetperms`
`.delmsgoncmd` | Toggles the automatic deletion of user's successful command message to prevent chat flood. **Requires Administrator server permission.** | `.delmsgoncmd`
`.setrole` `.sr` | Sets a role for a given user. **Requires ManageRoles server permission.** | `.sr @User Guest`
`.removerole` `.rr` | Removes a role from a given user. **Requires ManageRoles server permission.** | `.rr @User Admin`
`.setrole` `.sr` | Sets a role for a given user. **Requires ManageRoles server permission.** | `.sr @User Guest`
`.removerole` `.rr` | Removes a role from a given user. **Requires ManageRoles server permission.** | `.rr @User Admin`
`.renamerole` `.renr` | Renames a role. Roles you are renaming must be lower than bot's highest role. **Requires ManageRoles server permission.** | `.renr "First role" SecondRole`
`.removeallroles` `.rar` | Removes all roles from a mentioned user. **Requires ManageRoles server permission.** | `.rar @User`
`.createrole` `.cr` | Creates a role with a given name. **Requires ManageRoles server permission.** | `.cr Awesome Role`
`.rolecolor` `.rc` | Set a role's color to the hex or 0-255 rgb color value provided. **Requires ManageRoles server permission.** | `.rc Admin 255 200 100` or `.rc Admin ffba55`
`.removeallroles` `.rar` | Removes all roles from a mentioned user. **Requires ManageRoles server permission.** | `.rar @User`
`.createrole` `.cr` | Creates a role with a given name. **Requires ManageRoles server permission.** | `.cr Awesome Role`
`.rolecolor` `.rc` | Set a role's color to the hex or 0-255 rgb color value provided. **Requires ManageRoles server permission.** | `.rc Admin 255 200 100` or `.rc Admin ffba55`
`.ban` `.b` | Bans a user by ID or name with an optional message. **Requires BanMembers server permission.** | `.b "@some Guy" Your behaviour is toxic.`
`.softban` `.sb` | Bans and then unbans a user by ID or name with an optional message. **Requires KickMembers server permission.** **Requires ManageMessages server permission.** | `.sb "@some Guy" Your behaviour is toxic.`
`.kick` `.k` | Kicks a mentioned user. **Requires KickMembers server permission.** | `.k "@some Guy" Your behaviour is toxic.`
`.softban` `.sb` | Bans and then unbans a user by ID or name with an optional message. **Requires KickMembers server permission.** **Requires ManageMessages server permission.** | `.sb "@some Guy" Your behaviour is toxic.`
`.kick` `.k` | Kicks a mentioned user. **Requires KickMembers server permission.** | `.k "@some Guy" Your behaviour is toxic.`
`.setmuterole` | Sets a name of the role which will be assigned to people who should be muted. Default is nadeko-mute. After specifying this role, restart commands which use mute as punishment. **Requires ManageRoles server permission.** | `.setmuterole Silenced`
`.mute` | Mutes a mentioned user both from speaking and chatting. **Requires ManageRoles server permission.** **Requires MuteMembers server permission.** | `.mute @Someone`
`.unmute` | Unmutes a mentioned user previously muted with `.mute` command. **Requires ManageRoles server permission.** **Requires MuteMembers server permission.** | `.unmute @Someone`
`.chatmute` | Prevents a mentioned user from chatting in text channels. **Requires ManageRoles server permission.** | `.chatmute @Someone`
`.chatunmute` | Removes a mute role previously set on a mentioned user with `.chatmute` which prevented him from chatting in text channels. **Requires ManageRoles server permission.** | `.chatunmute @Someone`
`.voicemute` | Prevents a mentioned user from speaking in voice channels. **Requires MuteMembers server permission.** | `.voicemute @Someone`
`.voiceunmute` | Gives a previously voice-muted user a permission to speak. **Requires MuteMembers server permission.** | `.voiceunmute @Someguy`
`.deafen` `.deaf` | Deafens mentioned user or users. **Requires DeafenMembers server permission.** | `.deaf "@Someguy"` or `.deaf "@Someguy" "@Someguy"`
`.undeafen` `.undef` | Undeafens mentioned user or users. **Requires DeafenMembers server permission.** | `.undef "@Someguy"` or `.undef "@Someguy" "@Someguy"`
`.delvoichanl` `.dvch` | Deletes a voice channel with a given name. **Requires ManageChannels server permission.** | `.dvch VoiceChannelName`
`.creatvoichanl` `.cvch` | Creates a new voice channel with a given name. **Requires ManageChannels server permission.** | `.cvch VoiceChannelName`
`.deltxtchanl` `.dtch` | Deletes a text channel with a given name. **Requires ManageChannels server permission.** | `.dtch TextChannelName`
`.creatxtchanl` `.ctch` | Creates a new text channel with a given name. **Requires ManageChannels server permission.** | `.ctch TextChannelName`
`.settopic` `.st` | Sets a topic on the current channel. **Requires ManageChannels server permission.** | `.st My new topic`
`.setchanlname` `.schn` | Changes the name of the current channel. **Requires ManageChannels server permission.** | `.schn NewName`
`.prune` `.clr` | `.prune` removes all nadeko's messages in the last 100 messages.`.prune X` removes last X messages from the channel (up to 100)`.prune @Someone` removes all Someone's messages in the last 100 messages.`.prune @Someone X` removes last X 'Someone's' messages in the channel. | `.prune` or `.prune 5` or `.prune @Someone` or `.prune @Someone X`
`.voiceunmute` | Gives a previously voice-muted user a permission to speak. **Requires MuteMembers server permission.** | `.voiceunmute @Someguy`
`.deafen` `.deaf` | Deafens mentioned user or users. **Requires DeafenMembers server permission.** | `.deaf "@Someguy"` or `.deaf "@Someguy" "@Someguy"`
`.undeafen` `.undef` | Undeafens mentioned user or users. **Requires DeafenMembers server permission.** | `.undef "@Someguy"` or `.undef "@Someguy" "@Someguy"`
`.delvoichanl` `.dvch` | Deletes a voice channel with a given name. **Requires ManageChannels server permission.** | `.dvch VoiceChannelName`
`.creatvoichanl` `.cvch` | Creates a new voice channel with a given name. **Requires ManageChannels server permission.** | `.cvch VoiceChannelName`
`.deltxtchanl` `.dtch` | Deletes a text channel with a given name. **Requires ManageChannels server permission.** | `.dtch TextChannelName`
`.creatxtchanl` `.ctch` | Creates a new text channel with a given name. **Requires ManageChannels server permission.** | `.ctch TextChannelName`
`.settopic` `.st` | Sets a topic on the current channel. **Requires ManageChannels server permission.** | `.st My new topic`
`.setchanlname` `.schn` | Changes the name of the current channel. **Requires ManageChannels server permission.** | `.schn NewName`
`.prune` `.clr` | `.prune` removes all nadeko's messages in the last 100 messages.`.prune X` removes last X messages from the channel (up to 100)`.prune @Someone` removes all Someone's messages in the last 100 messages.`.prune @Someone X` removes last X 'Someone's' messages in the channel. | `.prune` or `.prune 5` or `.prune @Someone` or `.prune @Someone X`
`.die` | Shuts the bot down. **Bot owner only.** | `.die`
`.setname` `.newnm` | Gives the bot a new name. **Bot owner only.** | `.newnm BotName`
`.setavatar` `.setav` | Sets a new avatar image for the NadekoBot. Argument is a direct link to an image. **Bot owner only.** | `.setav http://i.imgur.com/xTG3a1I.jpg`
`.setgame` | Sets the bots game. **Bot owner only.** | `.setgame with snakes`
`.setname` `.newnm` | Gives the bot a new name. **Bot owner only.** | `.newnm BotName`
`.setavatar` `.setav` | Sets a new avatar image for the NadekoBot. Argument is a direct link to an image. **Bot owner only.** | `.setav http://i.imgur.com/xTG3a1I.jpg`
`.setgame` | Sets the bots game. **Bot owner only.** | `.setgame with snakes`
`.setstream` | Sets the bots stream. First argument is the twitch link, second argument is stream name. **Bot owner only.** | `.setstream https://www.twitch.tv/masterkwoth Developing Nakedo`
`.send` | Sends a message to someone on a different server through the bot. Separate server and channel/user ids with `|` and prepend channel id with `c:` and user id with `u:`. **Bot owner only.** | `.send serverid|c:channelid` or `.send serverid|u:userid`
`.announce` | Sends a message to all servers' general channel bot is connected to. **Bot owner only.** | `.announce Useless spam`
@ -57,23 +57,23 @@ Command and aliases | Description | Usage
`.donadd` | Add a donator to the database. **Bot owner only.** | `.donadd Donate Amount`
`.antiraid` | Sets an anti-raid protection on the server. First argument is number of people which will trigger the protection. Second one is a time interval in which that number of people needs to join in order to trigger the protection, and third argument is punishment for those people (Kick, Ban, Mute) **Requires Administrator server permission.** | `.antiraid 5 20 Kick`
`.antispam` | Stops people from repeating same message X times in a row. You can specify to either mute, kick or ban the offenders. **Requires Administrator server permission.** | `.antispam 3 Mute` or `.antispam 4 Kick` or `.antispam 6 Ban`
`.autoassignrole` `.aar` | Automaticaly assigns a specified role to every user who joins the server. **Requires ManageRoles server permission.** | `.aar` to disable, `.aar Role Name` to enable
`.autoassignrole` `.aar` | Automaticaly assigns a specified role to every user who joins the server. **Requires ManageRoles server permission.** | `.aar` to disable, `.aar Role Name` to enable
`.scsc` | Starts an instance of cross server channel. You will get a token as a DM that other people will use to tune in to the same instance. **Bot owner only.** | `.scsc`
`.jcsc` | Joins current channel to an instance of cross server channel using the token. **Requires ManageServer server permission.** | `.jcsc TokenHere`
`.lcsc` | Leaves Cross server channel instance from this channel. **Requires ManageServer server permission.** | `.lcsc`
`.jcsc` | Joins current channel to an instance of cross server channel using the token. **Requires ManageServer server permission.** | `.jcsc TokenHere`
`.lcsc` | Leaves Cross server channel instance from this channel. **Requires ManageServer server permission.** | `.lcsc`
`.fwmsgs` | Toggles forwarding of non-command messages sent to bot's DM to the bot owners **Bot owner only.** | `.fwmsgs`
`.fwtoall` | Toggles whether messages will be forwarded to all bot owners or only to the first one specified in the credentials.json **Bot owner only.** | `.fwtoall`
`.logserver` | Logs server activity in this channel. **Requires Administrator server permission.** **Bot owner only.** | `.logserver`
`.logignore` | Toggles whether the .logserver command ignores this channel. Useful if you have hidden admin channel and public log channel. **Requires Administrator server permission.** **Bot owner only.** | `.logignore`
`.userpresence` | Starts logging to this channel when someone from the server goes online/offline/idle. **Requires Administrator server permission.** | `.userpresence`
`.voicepresence` | Toggles logging to this channel whenever someone joins or leaves a voice channel you are currently in. **Requires Administrator server permission.** | `.voicepresence`
`.repeatinvoke` `.repinv` | Immediately shows the repeat message and restarts the timer. **Requires ManageMessages server permission.** | `.repinv`
`.userpresence` | Starts logging to this channel when someone from the server goes online/offline/idle. **Requires Administrator server permission.** | `.userpresence`
`.voicepresence` | Toggles logging to this channel whenever someone joins or leaves a voice channel you are currently in. **Requires Administrator server permission.** | `.voicepresence`
`.repeatinvoke` `.repinv` | Immediately shows the repeat message and restarts the timer. **Requires ManageMessages server permission.** | `.repinv`
`.repeat` | Repeat a message every X minutes. If no parameters are specified, repeat is disabled. | `.repeat 5 Hello there`
`.migratedata` | Migrate data from old bot configuration **Bot owner only.** | `.migratedata`
`.rotateplaying` `.ropl` | Toggles rotation of playing status of the dynamic strings you previously specified. **Bot owner only.** | `.ropl`
`.addplaying` `.adpl` | Adds a specified string to the list of playing strings to rotate. Supported placeholders: %servers%, %users%, %playing%, %queued% **Bot owner only.** | `.adpl`
`.listplaying` `.lipl` | Lists all playing statuses with their corresponding number. **Bot owner only.** | `.lipl`
`.removeplaying` `.rmpl` `.repl` | Removes a playing string on a given number. **Bot owner only.** | `.rmpl`
`.removeplaying` `.rmpl` `.repl` | Removes a playing string on a given number. **Bot owner only.** | `.rmpl`
`.slowmode` | Toggles slowmode. Disable by specifying no parameters. To enable, specify a number of messages each user can send, and an interval in seconds. For example 1 message every 5 seconds. **Requires ManageMessages server permission.** | `.slowmode 1 5` or `.slowmode`
`.adsarm` | Toggles the automatic deletion of confirmations for .iam and .iamn commands. **Requires ManageMessages server permission.** | `.adsarm`
`.asar` | Adds a role to the list of self-assignable roles. **Requires ManageRoles server permission.** | `.asar Gamer`
@ -82,16 +82,16 @@ Command and aliases | Description | Usage
`.togglexclsar` `.tesar` | Toggles whether the self-assigned roles are exclusive. (So that any person can have only one of the self assignable roles) **Requires ManageRoles server permission.** | `.tesar`
`.iam` | Adds a role to you that you choose. Role must be on a list of self-assignable roles. | `.iam Gamer`
`.iamnot` `.iamn` | Removes a role to you that you choose. Role must be on a list of self-assignable roles. | `.iamn Gamer`
`.leave` | Makes Nadeko leave the server. Either name or id required. **Bot owner only.** | `.leave 123123123331`
`.greetdel` `.grdel` | Toggles automatic deletion of greet messages. **Requires ManageServer server permission.** | `.greetdel`
`.greet` | Toggles anouncements on the current channel when someone joins the server. **Requires ManageServer server permission.** | `.greet`
`.greetmsg` | Sets a new join announcement message which will be shown in the server's channel. Type %user% if you want to mention the new member. Using it with no message will show the current greet message. **Requires ManageServer server permission.** | `.greetmsg Welcome, %user%.`
`.greetdm` | Toggles whether the greet messages will be sent in a DM (This is separate from greet - you can have both, any or neither enabled). **Requires ManageServer server permission.** | `.greetdm`
`.greetdmmsg` | Sets a new join announcement message which will be sent to the user who joined. Type %user% if you want to mention the new member. Using it with no message will show the current DM greet message. **Requires ManageServer server permission.** | `.greetdmmsg Welcome to the server, %user%`.
`.leave` | Makes Nadeko leave the server. Either name or id required. **Bot owner only.** | `.leave 123123123331`
`.greetdel` `.grdel` | Toggles automatic deletion of greet messages. **Requires ManageServer server permission.** | `.greetdel`
`.greet` | Toggles anouncements on the current channel when someone joins the server. **Requires ManageServer server permission.** | `.greet`
`.greetmsg` | Sets a new join announcement message which will be shown in the server's channel. Type %user% if you want to mention the new member. Using it with no message will show the current greet message. **Requires ManageServer server permission.** | `.greetmsg Welcome, %user%.`
`.greetdm` | Toggles whether the greet messages will be sent in a DM (This is separate from greet - you can have both, any or neither enabled). **Requires ManageServer server permission.** | `.greetdm`
`.greetdmmsg` | Sets a new join announcement message which will be sent to the user who joined. Type %user% if you want to mention the new member. Using it with no message will show the current DM greet message. **Requires ManageServer server permission.** | `.greetdmmsg Welcome to the server, %user%`.
`.bye` | Toggles anouncements on the current channel when someone leaves the server. **Requires ManageServer server permission.** | `.bye`
`.byemsg` | Sets a new leave announcement message. Type %user% if you want to mention the new member. Using it with no message will show the current bye message. **Requires ManageServer server permission.** | `.byemsg %user% has left.`
`.byedel` | Toggles automatic deletion of bye messages. **Requires ManageServer server permission.** | `.byedel`
`.voice+text` `.v+t` | Creates a text channel for each voice channel only users in that voice channel can see.If you are server owner, keep in mind you will see them all the time regardless. **Requires ManageRoles server permission.** **Requires ManageChannels server permission.** | `.voice+text`
`.byemsg` | Sets a new leave announcement message. Type %user% if you want to mention the new member. Using it with no message will show the current bye message. **Requires ManageServer server permission.** | `.byemsg %user% has left.`
`.byedel` | Toggles automatic deletion of bye messages. **Requires ManageServer server permission.** | `.byedel`
`.voice+text` `.v+t` | Creates a text channel for each voice channel only users in that voice channel can see.If you are server owner, keep in mind you will see them all the time regardless. **Requires ManageRoles server permission.** **Requires ManageChannels server permission.** | `.voice+text`
`.cleanvplust` `.cv+t` | Deletes all text channels ending in `-voice` for which voicechannels are not found. Use at your own risk. **Requires ManageChannels server permission.** **Requires ManageRoles server permission.** | `.cleanv+t`
###### [Back to TOC](#table-of-contents)
@ -128,7 +128,7 @@ Command and aliases | Description | Usage
`$cash` `$$$` | Check how much currency a person has. (Defaults to yourself) | `$$$` or `$$$ @SomeGuy`
`$give` | Give someone a certain amount of currency. | `$give 1 "@SomeGuy"`
`$award` | Awards someone a certain amount of currency. You can also specify a role name to award currency to all users in a role. **Bot owner only.** | `$award 100 @person` or `$award 5 Role Of Gamblers`
`$take` | Takes a certain amount of currency from someone. **Bot owner only.** | `$take 1 "@someguy"`
`$take` | Takes a certain amount of currency from someone. **Bot owner only.** | `$take 1 "@someguy"`
`$betroll` `$br` | Bets a certain amount of currency and rolls a dice. Rolling over 66 yields x2 of your currency, over 90 - x3 and 100 x10. | `$br 5`
`$leaderboard` `$lb` | Displays bot currency leaderboard. | `$lb`
`$race` | Starts a new animal race. | `$race`
@ -154,7 +154,7 @@ Command and aliases | Description | Usage
`>poll` | Creates a poll which requires users to send the number of the voting option to the bot. **Requires ManageMessages server permission.** | `>poll Question?;Answer1;Answ 2;A_3`
`>publicpoll` `>ppoll` | Creates a public poll which requires users to type a number of the voting option in the channel command is ran in. **Requires ManageMessages server permission.** | `>ppoll Question?;Answer1;Answ 2;A_3`
`>pollend` | Stops active poll on this server and prints the results in this channel. **Requires ManageMessages server permission.** | `>pollend`
`>cleverbot` | Toggles cleverbot session. When enabled, the bot will reply to messages starting with bot mention in the channel this command is ran in. You can specify "all" parameter to enable it in the whole server. Custom reactions starting with %mention% won't work if cleverbot is enabled.' **Requires ManageMessages server permission.** | `>cleverbot`
`>cleverbot` | Toggles cleverbot session. When enabled, the bot will reply to messages starting with bot mention in the server. Custom reactions starting with %mention% won't work if cleverbot is enabled. **Requires ManageMessages server permission.** | `>cleverbot`
`>pick` | Picks the currency planted in this channel. | `>pick`
`>plant` | Spend a unit of currency to plant it in this channel. (If bot is restarted or crashes, the currency will be lost) | `>plant`
`>gencurrency` `>gc` | Toggles currency generation on this channel. Every posted message will have chance to spawn currency. Chance is specified by the Bot Owner. (default is 2%) **Requires ManageMessages server permission.** | `>gc`
@ -347,6 +347,6 @@ Command and aliases | Description | Usage
`.deletequote` `.delq` | Deletes a random quote with the specified keyword. You have to either be server Administrator or the creator of the quote to delete it. | `.delq abc`
`.delallq` `.daq` | Deletes all quotes on a specified keyword. **Requires Administrator server permission.** | `.delallq kek`
`.remind` | 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. | `.remind me 1d5h Do something` or `.remind #general Start now!`
`.remindtemplate` | 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.** | `.remindtemplate %user%, you gotta do %message%!`
`.remindtemplate` | 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.** | `.remindtemplate %user%, you gotta do %message%!`
`.convertlist` | List of the convertible dimensions and currencies. | `.convertlist`
`.convert` | Convert quantities. Use `.convertlist` to see supported dimensions and currencies. | `.convert m km 1000`

View File

@ -5,6 +5,7 @@ using NadekoBot.Services;
using NadekoBot.Services.Database;
using Newtonsoft.Json;
using NLog;
using Services.CleverBotApi;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
@ -21,26 +22,27 @@ namespace NadekoBot.Modules.Games
[Group]
public class CleverBotCommands
{
private Logger _log { get; }
private static Logger _log { get; }
class CleverAnswer {
public string Status { get; set; }
public string Response { get; set; }
}
public CleverBotCommands()
{
_log = LogManager.GetCurrentClassLogger();
}
//user#discrim is the key
public static ConcurrentHashSet<string> ChannelsInConversation { get; } = new ConcurrentHashSet<string>();
public static ConcurrentHashSet<ulong> CleverbotGuilds { get; } = new ConcurrentHashSet<ulong>();
public static ConcurrentDictionary<ulong, ChatterBotSession> CleverbotGuilds { get; } = new ConcurrentDictionary<ulong, ChatterBotSession>();
static CleverBotCommands()
{
_log = LogManager.GetCurrentClassLogger();
using (var uow = DbHandler.UnitOfWork())
{
CleverbotGuilds = new ConcurrentHashSet<ulong>(uow.GuildConfigs.GetAll().Where(gc => gc.CleverbotEnabled).Select(gc => gc.GuildId));
var bot = ChatterBotFactory.Create(ChatterBotType.CLEVERBOT);
CleverbotGuilds = new ConcurrentDictionary<ulong, ChatterBotSession>(
uow.GuildConfigs.GetAll()
.Where(gc => gc.CleverbotEnabled)
.ToDictionary(gc => gc.GuildId, gc => bot.CreateSession()));
}
}
@ -50,9 +52,8 @@ namespace NadekoBot.Modules.Games
if (channel == null)
return false;
var nick = msg.Channel.Id + "NadekoBot";
if (!ChannelsInConversation.Contains(nick) && !CleverbotGuilds.Contains(channel.Guild.Id))
ChatterBotSession cleverbot;
if (!CleverbotGuilds.TryGetValue(channel.Guild.Id, out cleverbot))
return false;
var nadekoId = NadekoBot.Client.GetCurrentUser().Id;
@ -61,11 +62,11 @@ namespace NadekoBot.Modules.Games
string message;
if (msg.Content.StartsWith(normalMention))
{
message = msg.Content.Substring(normalMention.Length);
message = msg.Content.Substring(normalMention.Length).Trim();
}
else if (msg.Content.StartsWith(nickMention))
{
message = msg.Content.Substring(nickMention.Length);
message = msg.Content.Substring(nickMention.Length).Trim();
}
else
{
@ -74,98 +75,51 @@ namespace NadekoBot.Modules.Games
await msg.Channel.TriggerTypingAsync().ConfigureAwait(false);
using (var http = new HttpClient())
var response = await cleverbot.Think(message).ConfigureAwait(false);
try
{
var content = new FormUrlEncodedContent(new Dictionary<string, string>
{
{ "user", NadekoBot.Credentials.CleverbotApiUser},
{ "key", NadekoBot.Credentials.CleverbotApiKey},
{ "nick", nick},
{ "text", message},
});
var res = await http.PostAsync("https://cleverbot.io/1.0/ask", content).ConfigureAwait(false);
if (res.StatusCode == System.Net.HttpStatusCode.OK)
{
try
{
var answer = JsonConvert.DeserializeObject<CleverAnswer>(await res.Content.ReadAsStringAsync().ConfigureAwait(false));
try
{
await msg.Channel.SendMessageAsync(WebUtility.HtmlDecode(answer.Response)).ConfigureAwait(false);
}
catch
{
await msg.Channel.SendMessageAsync(answer.Response).ConfigureAwait(false); // try twice :\
}
}
catch { }
return true;
}
return false;
await msg.Channel.SendMessageAsync(response).ConfigureAwait(false);
}
catch (Exception ex)
{
_log.Warn(ex, "Eror sending response");
await msg.Channel.SendMessageAsync(response).ConfigureAwait(false); // try twice :\
}
return true;
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[RequirePermission(ChannelPermission.ManageMessages)]
public async Task Cleverbot(IUserMessage imsg, string all = null)
public async Task Cleverbot(IUserMessage imsg)
{
var channel = (ITextChannel)imsg.Channel;
if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.CleverbotApiKey) ||
string.IsNullOrWhiteSpace(NadekoBot.Credentials.CleverbotApiKey))
{
await channel.SendMessageAsync(":anger: `Bot owner didn't setup Cleverbot Api keys. Session will not start.`").ConfigureAwait(false);
return;
}
if (all?.Trim().ToLowerInvariant() == "all")
ChatterBotSession throwaway;
if (CleverbotGuilds.TryRemove(channel.Guild.Id, out throwaway))
{
var cleverbotEnabled = CleverbotGuilds.Add(channel.Guild.Id);
if (!cleverbotEnabled)
CleverbotGuilds.TryRemove(channel.Guild.Id);
using (var uow = DbHandler.UnitOfWork())
{
uow.GuildConfigs.SetCleverbotEnabled(channel.Guild.Id, cleverbotEnabled);
uow.GuildConfigs.SetCleverbotEnabled(channel.Guild.Id, false);
await uow.CompleteAsync().ConfigureAwait(false);
}
await channel.SendMessageAsync($"{imsg.Author.Mention} `{(cleverbotEnabled ? "Enabled" : "Disabled")} cleverbot for all users.`").ConfigureAwait(false);
await channel.SendMessageAsync($"{imsg.Author.Mention} `Disabled cleverbot on this server.`").ConfigureAwait(false);
return;
}
var cleverbot = ChatterBotFactory.Create(ChatterBotType.CLEVERBOT);
var session = cleverbot.CreateSession();
var nick = channel.Id + "NadekoBot";
CleverbotGuilds.TryAdd(channel.Guild.Id, session);
if (ChannelsInConversation.TryRemove(nick))
using (var uow = DbHandler.UnitOfWork())
{
await channel.SendMessageAsync($"{imsg.Author.Mention} `I will no longer reply to your messages starting with my mention.`").ConfigureAwait(false);
return;
uow.GuildConfigs.SetCleverbotEnabled(channel.Guild.Id, true);
await uow.CompleteAsync().ConfigureAwait(false);
}
using (var http = new HttpClient())
{
var content = new FormUrlEncodedContent(new Dictionary<string, string>()
{
{ "user", NadekoBot.Credentials.CleverbotApiUser},
{ "key", NadekoBot.Credentials.CleverbotApiKey},
{ "nick", nick},
});
var res = await http.PostAsync("https://cleverbot.io/1.0/create", content).ConfigureAwait(false);
if (res.StatusCode != System.Net.HttpStatusCode.OK)
{
await channel.SendMessageAsync($"{imsg.Author.Mention} `Something went wrong in starting your cleverbot session :\\`");
_log.Warn(await res.Content.ReadAsStringAsync());
return;
}
ChannelsInConversation.Add(nick);
}
await channel.SendMessageAsync($"{imsg.Author.Mention} `I will reply to your messages starting with my mention.`").ConfigureAwait(false);
await channel.SendMessageAsync($"{imsg.Author.Mention} `Enabled cleverbot on this server.`").ConfigureAwait(false);
}
}
}
}

View File

@ -128,7 +128,7 @@ namespace NadekoBot.Modules.Help
helpstr.AppendLine(@"For more information and how to setup your own NadekoBot, go to: <http://github.com/Kwoth/NadekoBot/wiki>
You can support the project on patreon: <https://patreon.com/nadekobot> or paypal: `nadekodiscordbot@gmail.com`");
helpstr.AppendLine("##Table Of Contents");
helpstr.AppendLine(string.Join("\n", NadekoBot.CommandService.Modules.Select(m => $"- [{m.Name}](#{m.Name.ToLowerInvariant()})")));
helpstr.AppendLine(string.Join("\n", NadekoBot.CommandService.Modules.Where(m => m.Name.ToLowerInvariant() != "help").OrderBy(m => m.Name).Prepend(NadekoBot.CommandService.Modules.FirstOrDefault(m=>m.Name.ToLowerInvariant()=="help")).Select(m => $"- [{m.Name}](#{m.Name.ToLowerInvariant()})")));
helpstr.AppendLine();
string lastModule = null;
foreach (var com in _commands.Commands.OrderBy(com=>com.Module.Name).GroupBy(c=>c.Text).Select(g=>g.First()))

View File

@ -59,7 +59,7 @@ namespace NadekoBot.Modules.Searches
.ConfigureAwait(false);
if (autoDelete)
try { await umsg.DeleteAsync().ConfigureAwait(false); } catch { }
await umsg.Channel.SendMessageAsync($"{umsg.Author.Mention} `said:` "+text.Replace("<@ ", "<@").Replace("<@! ", "<@!")).ConfigureAwait(false);
await umsg.Channel.SendMessageAsync($"{umsg.Author.Mention} `:` "+text.Replace("<@ ", "<@").Replace("<@! ", "<@!")).ConfigureAwait(false);
}
catch { }
@ -161,6 +161,7 @@ namespace NadekoBot.Modules.Searches
if (!GoogleTranslator.Instance.Languages.Contains(from) || !GoogleTranslator.Instance.Languages.Contains(to))
{
try { await channel.SendMessageAsync("`Invalid source and/or target Language.`").ConfigureAwait(false); } catch { }
return;
}
UserLanguages.AddOrUpdate(ucp, langs, (key, val) => langs);

View File

@ -166,7 +166,7 @@
<value>greetdel grdel</value>
</data>
<data name="greetdel_desc" xml:space="preserve">
<value>Toggles automatic deletion of greet messages. </value>
<value>Toggles automatic deletion of greet messages.</value>
</data>
<data name="greetdel_usage" xml:space="preserve">
<value>`{0}greetdel`</value>
@ -175,7 +175,7 @@
<value>greet</value>
</data>
<data name="greet_desc" xml:space="preserve">
<value>Toggles anouncements on the current channel when someone joins the server. </value>
<value>Toggles anouncements on the current channel when someone joins the server.</value>
</data>
<data name="greet_usage" xml:space="preserve">
<value>`{0}greet`</value>
@ -184,7 +184,7 @@
<value>greetmsg</value>
</data>
<data name="greetmsg_desc" xml:space="preserve">
<value>Sets a new join announcement message which will be shown in the server's channel. Type %user% if you want to mention the new member. Using it with no message will show the current greet message. </value>
<value>Sets a new join announcement message which will be shown in the server's channel. Type %user% if you want to mention the new member. Using it with no message will show the current greet message.</value>
</data>
<data name="greetmsg_usage" xml:space="preserve">
<value>`{0}greetmsg Welcome, %user%.`</value>
@ -202,7 +202,7 @@
<value>byemsg</value>
</data>
<data name="byemsg_desc" xml:space="preserve">
<value>Sets a new leave announcement message. Type %user% if you want to mention the new member. Using it with no message will show the current bye message. </value>
<value>Sets a new leave announcement message. Type %user% if you want to mention the new member. Using it with no message will show the current bye message.</value>
</data>
<data name="byemsg_usage" xml:space="preserve">
<value>`{0}byemsg %user% has left.`</value>
@ -211,7 +211,7 @@
<value>byedel</value>
</data>
<data name="byedel_desc" xml:space="preserve">
<value>Toggles automatic deletion of bye messages. </value>
<value>Toggles automatic deletion of bye messages.</value>
</data>
<data name="byedel_usage" xml:space="preserve">
<value>`{0}byedel`</value>
@ -220,7 +220,7 @@
<value>greetdm</value>
</data>
<data name="greetdm_desc" xml:space="preserve">
<value>Toggles whether the greet messages will be sent in a DM (This is separate from greet - you can have both, any or neither enabled). </value>
<value>Toggles whether the greet messages will be sent in a DM (This is separate from greet - you can have both, any or neither enabled).</value>
</data>
<data name="greetdm_usage" xml:space="preserve">
<value>`{0}greetdm`</value>
@ -247,7 +247,7 @@
<value>userpresence</value>
</data>
<data name="userpresence_desc" xml:space="preserve">
<value>Starts logging to this channel when someone from the server goes online/offline/idle. </value>
<value>Starts logging to this channel when someone from the server goes online/offline/idle.</value>
</data>
<data name="userpresence_usage" xml:space="preserve">
<value>`{0}userpresence`</value>
@ -256,7 +256,7 @@
<value>voicepresence</value>
</data>
<data name="voicepresence_desc" xml:space="preserve">
<value>Toggles logging to this channel whenever someone joins or leaves a voice channel you are currently in. </value>
<value>Toggles logging to this channel whenever someone joins or leaves a voice channel you are currently in.</value>
</data>
<data name="voicepresence_usage" xml:space="preserve">
<value>`{0}voicepresence`</value>
@ -265,7 +265,7 @@
<value>repeatinvoke repinv</value>
</data>
<data name="repeatinvoke_desc" xml:space="preserve">
<value>Immediately shows the repeat message and restarts the timer. </value>
<value>Immediately shows the repeat message and restarts the timer.</value>
</data>
<data name="repeatinvoke_usage" xml:space="preserve">
<value>`{0}repinv`</value>
@ -310,7 +310,7 @@
<value>removeplaying rmpl repl</value>
</data>
<data name="removeplaying_desc" xml:space="preserve">
<value>Removes a playing string on a given number. </value>
<value>Removes a playing string on a given number.</value>
</data>
<data name="removeplaying_usage" xml:space="preserve">
<value>`{0}rmpl`</value>
@ -337,7 +337,7 @@
<value>voice+text v+t</value>
</data>
<data name="voiceplustext_desc" xml:space="preserve">
<value>Creates a text channel for each voice channel only users in that voice channel can see.If you are server owner, keep in mind you will see them all the time regardless. </value>
<value>Creates a text channel for each voice channel only users in that voice channel can see.If you are server owner, keep in mind you will see them all the time regardless.</value>
</data>
<data name="voiceplustext_usage" xml:space="preserve">
<value>`{0}voice+text`</value>
@ -355,7 +355,7 @@
<value>jcsc</value>
</data>
<data name="jcsc_desc" xml:space="preserve">
<value>Joins current channel to an instance of cross server channel using the token. </value>
<value>Joins current channel to an instance of cross server channel using the token.</value>
</data>
<data name="jcsc_usage" xml:space="preserve">
<value>`{0}jcsc TokenHere`</value>
@ -364,7 +364,7 @@
<value>lcsc</value>
</data>
<data name="lcsc_desc" xml:space="preserve">
<value>Leaves Cross server channel instance from this channel. </value>
<value>Leaves Cross server channel instance from this channel.</value>
</data>
<data name="lcsc_usage" xml:space="preserve">
<value>`{0}lcsc`</value>
@ -463,7 +463,7 @@
<value>autoassignrole aar</value>
</data>
<data name="autoassignrole_desc" xml:space="preserve">
<value>Automaticaly assigns a specified role to every user who joins the server. </value>
<value>Automaticaly assigns a specified role to every user who joins the server.</value>
</data>
<data name="autoassignrole_usage" xml:space="preserve">
<value>`{0}aar` to disable, `{0}aar Role Name` to enable</value>
@ -472,7 +472,7 @@
<value>leave</value>
</data>
<data name="leave_desc" xml:space="preserve">
<value>Makes Nadeko leave the server. Either name or id required. </value>
<value>Makes Nadeko leave the server. Either name or id required.</value>
</data>
<data name="leave_usage" xml:space="preserve">
<value>`{0}leave 123123123331`</value>
@ -499,7 +499,7 @@
<value>setrole sr</value>
</data>
<data name="setrole_desc" xml:space="preserve">
<value>Sets a role for a given user. </value>
<value>Sets a role for a given user.</value>
</data>
<data name="setrole_usage" xml:space="preserve">
<value>`{0}sr @User Guest`</value>
@ -508,7 +508,7 @@
<value>removerole rr</value>
</data>
<data name="removerole_desc" xml:space="preserve">
<value>Removes a role from a given user. </value>
<value>Removes a role from a given user.</value>
</data>
<data name="removerole_usage" xml:space="preserve">
<value>`{0}rr @User Admin`</value>
@ -526,7 +526,7 @@
<value>removeallroles rar</value>
</data>
<data name="removeallroles_desc" xml:space="preserve">
<value>Removes all roles from a mentioned user. </value>
<value>Removes all roles from a mentioned user.</value>
</data>
<data name="removeallroles_usage" xml:space="preserve">
<value>`{0}rar @User`</value>
@ -535,7 +535,7 @@
<value>createrole cr</value>
</data>
<data name="createrole_desc" xml:space="preserve">
<value>Creates a role with a given name. </value>
<value>Creates a role with a given name.</value>
</data>
<data name="createrole_usage" xml:space="preserve">
<value>`{0}cr Awesome Role`</value>
@ -544,7 +544,7 @@
<value>rolecolor rc</value>
</data>
<data name="rolecolor_desc" xml:space="preserve">
<value>Set a role's color to the hex or 0-255 rgb color value provided. </value>
<value>Set a role's color to the hex or 0-255 rgb color value provided.</value>
</data>
<data name="rolecolor_usage" xml:space="preserve">
<value>`{0}rc Admin 255 200 100` or `{0}rc Admin ffba55`</value>
@ -562,7 +562,7 @@
<value>softban sb</value>
</data>
<data name="softban_desc" xml:space="preserve">
<value>Bans and then unbans a user by ID or name with an optional message. </value>
<value>Bans and then unbans a user by ID or name with an optional message.</value>
</data>
<data name="softban_usage" xml:space="preserve">
<value>`{0}sb "@some Guy" Your behaviour is toxic.`</value>
@ -571,7 +571,7 @@
<value>kick k</value>
</data>
<data name="kick_desc" xml:space="preserve">
<value>Kicks a mentioned user. </value>
<value>Kicks a mentioned user.</value>
</data>
<data name="kick_usage" xml:space="preserve">
<value>`{0}k "@some Guy" Your behaviour is toxic.`</value>
@ -589,7 +589,7 @@
<value>voiceunmute</value>
</data>
<data name="voiceunmute_desc" xml:space="preserve">
<value>Gives a previously voice-muted user a permission to speak. </value>
<value>Gives a previously voice-muted user a permission to speak.</value>
</data>
<data name="voiceunmute_usage" xml:space="preserve">
<value>`{0}voiceunmute @Someguy`</value>
@ -598,7 +598,7 @@
<value>deafen deaf</value>
</data>
<data name="deafen_desc" xml:space="preserve">
<value>Deafens mentioned user or users. </value>
<value>Deafens mentioned user or users.</value>
</data>
<data name="deafen_usage" xml:space="preserve">
<value>`{0}deaf "@Someguy"` or `{0}deaf "@Someguy" "@Someguy"`</value>
@ -607,7 +607,7 @@
<value>undeafen undef</value>
</data>
<data name="undeafen_desc" xml:space="preserve">
<value>Undeafens mentioned user or users. </value>
<value>Undeafens mentioned user or users.</value>
</data>
<data name="undeafen_usage" xml:space="preserve">
<value>`{0}undef "@Someguy"` or `{0}undef "@Someguy" "@Someguy"`</value>
@ -616,7 +616,7 @@
<value>delvoichanl dvch</value>
</data>
<data name="delvoichanl_desc" xml:space="preserve">
<value>Deletes a voice channel with a given name. </value>
<value>Deletes a voice channel with a given name.</value>
</data>
<data name="delvoichanl_usage" xml:space="preserve">
<value>`{0}dvch VoiceChannelName`</value>
@ -625,7 +625,7 @@
<value>creatvoichanl cvch</value>
</data>
<data name="creatvoichanl_desc" xml:space="preserve">
<value>Creates a new voice channel with a given name. </value>
<value>Creates a new voice channel with a given name.</value>
</data>
<data name="creatvoichanl_usage" xml:space="preserve">
<value>`{0}cvch VoiceChannelName`</value>
@ -634,7 +634,7 @@
<value>deltxtchanl dtch</value>
</data>
<data name="deltxtchanl_desc" xml:space="preserve">
<value>Deletes a text channel with a given name. </value>
<value>Deletes a text channel with a given name.</value>
</data>
<data name="deltxtchanl_usage" xml:space="preserve">
<value>`{0}dtch TextChannelName`</value>
@ -643,7 +643,7 @@
<value>creatxtchanl ctch</value>
</data>
<data name="creatxtchanl_desc" xml:space="preserve">
<value>Creates a new text channel with a given name. </value>
<value>Creates a new text channel with a given name.</value>
</data>
<data name="creatxtchanl_usage" xml:space="preserve">
<value>`{0}ctch TextChannelName`</value>
@ -652,7 +652,7 @@
<value>settopic st</value>
</data>
<data name="settopic_desc" xml:space="preserve">
<value>Sets a topic on the current channel. </value>
<value>Sets a topic on the current channel.</value>
</data>
<data name="settopic_usage" xml:space="preserve">
<value>`{0}st My new topic`</value>
@ -661,7 +661,7 @@
<value>setchanlname schn</value>
</data>
<data name="setchanlname_desc" xml:space="preserve">
<value>Changes the name of the current channel. </value>
<value>Changes the name of the current channel.</value>
</data>
<data name="setchanlname_usage" xml:space="preserve">
<value>`{0}schn NewName`</value>
@ -670,7 +670,7 @@
<value>prune clr</value>
</data>
<data name="prune_desc" xml:space="preserve">
<value>`{0}prune` removes all nadeko's messages in the last 100 messages.`{0}prune X` removes last X messages from the channel (up to 100)`{0}prune @Someone` removes all Someone's messages in the last 100 messages.`{0}prune @Someone X` removes last X 'Someone's' messages in the channel. </value>
<value>`{0}prune` removes all nadeko's messages in the last 100 messages.`{0}prune X` removes last X messages from the channel (up to 100)`{0}prune @Someone` removes all Someone's messages in the last 100 messages.`{0}prune @Someone X` removes last X 'Someone's' messages in the channel.</value>
</data>
<data name="prune_usage" xml:space="preserve">
<value>`{0}prune` or `{0}prune 5` or `{0}prune @Someone` or `{0}prune @Someone X`</value>
@ -688,7 +688,7 @@
<value>setname newnm</value>
</data>
<data name="setname_desc" xml:space="preserve">
<value>Gives the bot a new name. </value>
<value>Gives the bot a new name.</value>
</data>
<data name="setname_usage" xml:space="preserve">
<value>`{0}newnm BotName`</value>
@ -697,7 +697,7 @@
<value>setavatar setav</value>
</data>
<data name="setavatar_desc" xml:space="preserve">
<value>Sets a new avatar image for the NadekoBot. Argument is a direct link to an image. </value>
<value>Sets a new avatar image for the NadekoBot. Argument is a direct link to an image.</value>
</data>
<data name="setavatar_usage" xml:space="preserve">
<value>`{0}setav http://i.imgur.com/xTG3a1I.jpg`</value>
@ -706,7 +706,7 @@
<value>setgame</value>
</data>
<data name="setgame_desc" xml:space="preserve">
<value>Sets the bots game. </value>
<value>Sets the bots game.</value>
</data>
<data name="setgame_usage" xml:space="preserve">
<value>`{0}setgame with snakes`</value>
@ -733,7 +733,7 @@
<value>unstuck</value>
</data>
<data name="unstuck_desc" xml:space="preserve">
<value>Clears the message queue. </value>
<value>Clears the message queue.</value>
</data>
<data name="unstuck_usage" xml:space="preserve">
<value>`{0}unstuck`</value>
@ -787,7 +787,7 @@
<value>remindtemplate</value>
</data>
<data name="remindtemplate_desc" xml:space="preserve">
<value>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. </value>
<value>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.</value>
</data>
<data name="remindtemplate_usage" xml:space="preserve">
<value>`{0}remindtemplate %user%, you gotta do %message%!`</value>
@ -1255,7 +1255,7 @@
<value>take</value>
</data>
<data name="take_desc" xml:space="preserve">
<value>Takes a certain amount of currency from someone. </value>
<value>Takes a certain amount of currency from someone.</value>
</data>
<data name="take_usage" xml:space="preserve">
<value>`{0}take 1 "@someguy"`</value>
@ -1615,7 +1615,7 @@
<value>cleanup</value>
</data>
<data name="cleanup_desc" xml:space="preserve">
<value>Cleans up hanging voice connections. </value>
<value>Cleans up hanging voice connections.</value>
</data>
<data name="cleanup_usage" xml:space="preserve">
<value>`{0}cleanup`</value>
@ -2311,7 +2311,7 @@
<value>`{0}greetdmmsg Welcome to the server, %user%`.</value>
</data>
<data name="greetdmmsg_desc" xml:space="preserve">
<value>Sets a new join announcement message which will be sent to the user who joined. Type %user% if you want to mention the new member. Using it with no message will show the current DM greet message. </value>
<value>Sets a new join announcement message which will be sent to the user who joined. Type %user% if you want to mention the new member. Using it with no message will show the current DM greet message.</value>
</data>
<data name="cash_desc" xml:space="preserve">
<value>Check how much currency a person has. (Defaults to yourself)</value>
@ -2623,7 +2623,7 @@
<value>cleverbot</value>
</data>
<data name="cleverbot_desc" xml:space="preserve">
<value>Toggles cleverbot session. When enabled, the bot will reply to messages starting with bot mention in the channel this command is ran in. You can specify "all" parameter to enable it in the whole server. Custom reactions starting with %mention% won't work if cleverbot is enabled.' </value>
<value>Toggles cleverbot session. When enabled, the bot will reply to messages starting with bot mention in the server. Custom reactions starting with %mention% won't work if cleverbot is enabled.</value>
</data>
<data name="cleverbot_usage" xml:space="preserve">
<value>`{0}cleverbot`</value>

View File

@ -0,0 +1,25 @@
/*
ChatterBotAPI
Copyright (C) 2011 pierredavidbelanger@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Services.CleverBotApi
{
public interface ChatterBot
{
ChatterBotSession CreateSession();
}
}

View File

@ -0,0 +1,45 @@
using System;
/*
ChatterBotAPI
Copyright (C) 2011 pierredavidbelanger@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Services.CleverBotApi
{
public class ChatterBotFactory
{
public static ChatterBot Create(ChatterBotType type)
{
return Create(type, null);
}
public static ChatterBot Create(ChatterBotType type, object arg)
{
switch (type)
{
case ChatterBotType.CLEVERBOT:
return new Cleverbot("http://www.cleverbot.com/", "http://www.cleverbot.com/webservicemin?uc=165", 26);
case ChatterBotType.JABBERWACKY:
return new Cleverbot("http://jabberwacky.com", "http://jabberwacky.com/webservicemin", 20);
case ChatterBotType.PANDORABOTS:
if (arg == null) throw new ArgumentException("PANDORABOTS needs a botid arg", nameof(arg));
return new Pandorabots(arg.ToString());
}
return null;
}
}
}

View File

@ -0,0 +1,28 @@
/*
ChatterBotAPI
Copyright (C) 2011 pierredavidbelanger@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System.Threading.Tasks;
namespace Services.CleverBotApi
{
public interface ChatterBotSession
{
Task<ChatterBotThought> Think(ChatterBotThought thought);
Task<string> Think(string text);
}
}

View File

@ -0,0 +1,26 @@
/*
ChatterBotAPI
Copyright (C) 2011 pierredavidbelanger@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Services.CleverBotApi
{
public class ChatterBotThought
{
public string[] Emotions { get; set; }
public string Text { get; set; }
}
}

View File

@ -0,0 +1,27 @@
/*
ChatterBotAPI
Copyright (C) 2011 pierredavidbelanger@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Services.CleverBotApi
{
public enum ChatterBotType
{
CLEVERBOT,
JABBERWACKY,
PANDORABOTS
}
}

View File

@ -0,0 +1,116 @@
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
/*
ChatterBotAPI
Copyright (C) 2011 pierredavidbelanger@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Services.CleverBotApi
{
internal class Cleverbot : ChatterBot
{
private readonly int endIndex;
private readonly string baseUrl;
private readonly string url;
public Cleverbot(string baseUrl, string url, int endIndex)
{
this.baseUrl = baseUrl;
this.url = url;
this.endIndex = endIndex;
}
public ChatterBotSession CreateSession()
{
return new CleverbotSession(baseUrl, url, endIndex);
}
}
internal class CleverbotSession : ChatterBotSession
{
private readonly int endIndex;
private readonly string url;
private readonly IDictionary<string, string> vars;
private readonly CookieCollection cookies;
public CleverbotSession(string baseUrl, string url, int endIndex)
{
this.url = url;
this.endIndex = endIndex;
vars = new Dictionary<string, string>();
//vars["start"] = "y";
vars["stimulus"] = "";
vars["islearning"] = "1";
vars["icognoid"] = "wsf";
//vars["fno"] = "0";
//vars["sub"] = "Say";
//vars["cleanslate"] = "false";
cookies = Utils.GetCookies(baseUrl);
}
public async Task<ChatterBotThought> Think(ChatterBotThought thought)
{
vars["stimulus"] = thought.Text;
var formData = Utils.ParametersToWWWFormURLEncoded(vars);
var formDataToDigest = formData.Substring(9, endIndex);
var formDataDigest = Utils.MD5(formDataToDigest);
vars["icognocheck"] = formDataDigest;
var response = await Utils.Post(url, vars, cookies).ConfigureAwait(false);
var responseValues = response.Split('\r');
//vars[""] = Utils.StringAtIndex(responseValues, 0); ??
vars["sessionid"] = Utils.StringAtIndex(responseValues, 1);
vars["logurl"] = Utils.StringAtIndex(responseValues, 2);
vars["vText8"] = Utils.StringAtIndex(responseValues, 3);
vars["vText7"] = Utils.StringAtIndex(responseValues, 4);
vars["vText6"] = Utils.StringAtIndex(responseValues, 5);
vars["vText5"] = Utils.StringAtIndex(responseValues, 6);
vars["vText4"] = Utils.StringAtIndex(responseValues, 7);
vars["vText3"] = Utils.StringAtIndex(responseValues, 8);
vars["vText2"] = Utils.StringAtIndex(responseValues, 9);
vars["prevref"] = Utils.StringAtIndex(responseValues, 10);
//vars[""] = Utils.StringAtIndex(responseValues, 11); ??
// vars["emotionalhistory"] = Utils.StringAtIndex(responseValues, 12);
// vars["ttsLocMP3"] = Utils.StringAtIndex(responseValues, 13);
// vars["ttsLocTXT"] = Utils.StringAtIndex(responseValues, 14);
// vars["ttsLocTXT3"] = Utils.StringAtIndex(responseValues, 15);
// vars["ttsText"] = Utils.StringAtIndex(responseValues, 16);
// vars["lineRef"] = Utils.StringAtIndex(responseValues, 17);
// vars["lineURL"] = Utils.StringAtIndex(responseValues, 18);
// vars["linePOST"] = Utils.StringAtIndex(responseValues, 19);
// vars["lineChoices"] = Utils.StringAtIndex(responseValues, 20);
// vars["lineChoicesAbbrev"] = Utils.StringAtIndex(responseValues, 21);
// vars["typingData"] = Utils.StringAtIndex(responseValues, 22);
// vars["divert"] = Utils.StringAtIndex(responseValues, 23);
var responseThought = new ChatterBotThought();
responseThought.Text = Utils.StringAtIndex(responseValues, 0);
return responseThought;
}
public async Task<string> Think(string text)
{
return (await Think(new ChatterBotThought {Text = text}).ConfigureAwait(false)).Text;
}
}
}

View File

@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
/*
ChatterBotAPI
Copyright (C) 2011 pierredavidbelanger@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Services.CleverBotApi
{
internal class Pandorabots : ChatterBot
{
private readonly string botid;
public Pandorabots(string botid)
{
this.botid = botid;
}
public ChatterBotSession CreateSession()
{
return new PandorabotsSession(botid);
}
}
internal class PandorabotsSession : ChatterBotSession
{
private readonly IDictionary<string, string> vars;
public PandorabotsSession(string botid)
{
vars = new Dictionary<string, string>();
vars["botid"] = botid;
vars["custid"] = Guid.NewGuid().ToString();
}
public async Task<ChatterBotThought> Think(ChatterBotThought thought)
{
vars["input"] = thought.Text;
var response = await Utils.Post("http://www.pandorabots.com/pandora/talk-xml", vars, null).ConfigureAwait(false);
var responseThought = new ChatterBotThought();
responseThought.Text = Utils.XPathSearch(response, "//result/that/text()");
return responseThought;
}
public async Task<string> Think(string text)
{
return (await Think(new ChatterBotThought {Text = text}).ConfigureAwait(false)).Text;
}
}
}

View File

@ -0,0 +1,148 @@
using NadekoBot.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Xml.XPath;
/*
ChatterBotAPI
Copyright (C) 2011 pierredavidbelanger@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Services.CleverBotApi
{
internal static class Utils
{
public static string ParametersToWWWFormURLEncoded(IDictionary<string, string> parameters)
{
string wwwFormUrlEncoded = null;
foreach (var parameterKey in parameters.Keys)
{
var parameterValue = parameters[parameterKey];
var parameter = string.Format("{0}={1}", System.Uri.EscapeDataString(parameterKey), System.Uri.EscapeDataString(parameterValue));
if (wwwFormUrlEncoded == null)
{
wwwFormUrlEncoded = parameter;
}
else
{
wwwFormUrlEncoded = string.Format("{0}&{1}", wwwFormUrlEncoded, parameter);
}
}
return wwwFormUrlEncoded;
}
public static string MD5(string input)
{
// step 1, calculate MD5 hash from input
var md5 = System.Security.Cryptography.MD5.Create();
var inputBytes = Encoding.ASCII.GetBytes(input);
var hash = md5.ComputeHash(inputBytes);
// step 2, convert byte array to hex string
var sb = new StringBuilder();
for (var i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("X2"));
}
return sb.ToString();
}
public static CookieCollection GetCookies(string url)
{
CookieContainer container = new CookieContainer();
HttpResponseMessage res;
using (var handler = new HttpClientHandler() { CookieContainer = container })
using (var http = new HttpClient(handler))
{
http.AddFakeHeaders();
http.DefaultRequestHeaders.Add("ContentType", "text/html");
res = http.GetAsync(url).GetAwaiter().GetResult();
}
var response = res.Content.ReadAsStringAsync().GetAwaiter().GetResult();
return container.GetCookies(res.RequestMessage.RequestUri);
}
public static async Task<string> Post(string url, IDictionary<string, string> parameters, CookieCollection cookies)
{
var postData = ParametersToWWWFormURLEncoded(parameters);
var postDataBytes = Encoding.ASCII.GetBytes(postData);
var request = (HttpWebRequest)WebRequest.Create(url);
if (cookies != null)
{
var container = new CookieContainer();
container.Add(new Uri(url), cookies);
request.CookieContainer = container;
}
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
using (var outputStream = await request.GetRequestStreamAsync())
{
outputStream.Write(postDataBytes, 0, postDataBytes.Length);
outputStream.Flush();
var response = (HttpWebResponse)await request.GetResponseAsync();
using (var responseStreamReader = new StreamReader(response.GetResponseStream()))
{
return responseStreamReader.ReadToEnd().Trim();
}
}
//HttpClientHandler handler;
//var uri = new Uri(url);
//if (cookies == null)
// handler = new HttpClientHandler();
//else
//{
// var cookieContainer = new CookieContainer();
// cookieContainer.Add(uri, cookies);
// handler = new HttpClientHandler() { CookieContainer = cookieContainer };
//}
//using (handler)
//using (var http = new HttpClient(handler))
//{
// var res = await http.PostAsync(url, new FormUrlEncodedContent(parameters)).ConfigureAwait(false);
// return await res.Content.ReadAsStringAsync().ConfigureAwait(false);
//}
}
public static string XPathSearch(string input, string expression)
{
var document = new XPathDocument(new MemoryStream(Encoding.ASCII.GetBytes(input)));
var navigator = document.CreateNavigator();
return navigator.SelectSingleNode(expression).Value.Trim();
}
public static string StringAtIndex(string[] strings, int index)
{
if (index >= strings.Length) return "";
return strings[index];
}
}
}

View File

@ -26,8 +26,6 @@ namespace NadekoBot.Services.Impl
public string LoLApiKey { get; }
public string OsuApiKey { get; }
public string SoundCloudClientId { get; }
public string CleverbotApiUser { get; }
public string CleverbotApiKey { get; }
public DB Db { get; }
public int TotalShards { get; }
@ -52,8 +50,6 @@ namespace NadekoBot.Services.Impl
ClientId = cm.ClientId;
SoundCloudClientId = cm.SoundCloudClientId;
CarbonKey = cm.CarbonKey;
CleverbotApiKey = cm.CleverbotApiKey;
CleverbotApiUser = cm.CleverbotApiUser;
if (cm.Db == null)
Db = new DB("sqlite", "");
else
@ -81,8 +77,6 @@ namespace NadekoBot.Services.Impl
public string CarbonKey { get; set; } = "";
public DB Db { get; set; }
public int TotalShards { get; set; } = 1;
public string CleverbotApiUser { get; set; }
public string CleverbotApiKey { get; set; }
}
private class DbModel

View File

@ -12,7 +12,5 @@
"SoundCloudClientId": "",
"CarbonKey": "",
"Db": null,
"TotalShards": 1,
"CleverbotApiUser": null,
"CleverbotApiKey": null
"TotalShards": 1
}

View File

@ -41,7 +41,8 @@
},
"Discord.Net": {
"target": "project"
}
},
"System.Xml.XPath": "4.0.1"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"