IYP Bot

Published August 16, 2016
Advertisement

So as you know, GDN chat was recently moved to discord, and with discord comes the ability to write a bot. So i thought to write a bot so that users can program it. The main idea behind it was to make a bot that people could contribute to, to teach it language. Though it started that way, but after seeing people's usage of it the idea completely changed to programmable bot. So as the bot got more complicated so did the syntax, and that made a few people to be able to use it. So i thought to introduce my bot with a full documentation.

The idea is to categorize the messages the users in the chat send. All the messages in one category share the same group of responses. So you can say in a category you have an array of messages and an array of responses. If a message is recognized of a category, a random response from that category will be replied by the bot. If the category doesn't contain any responses the category name is replied by the bot.

Syntax to add a message to a category:.add_message [category name] message

Syntax to add a response to a category:.add_response [category name] message

If you use a category name that doesn't exist, it will create that category.

Note: messages and categories are stored in the order the user have added them. That means if a messages if recognized of a specific category the other categories that were added after that category wont be checked. Same is true for messages, if a user sent message is recognized as a message stored in a category, the messages added after that message to the category wont be checked.

Example (on the examples the user name is IYP (which is me :D ) and the bot is IYPBOT): IYP.add_message [greeting_message] hello IYPBOTMessage added IYPhello IYPBOT[greeting_message] IYP.add_response [greeting_message] hey IYPBOTResponse added IYPhello IYPBOThey

Tags: @me, @sender
You can use @me tag as a placeholder to the bot's mention tag.
@sender is a placeholder to user's mention tag.

Example:IYP.add_message [greeting_message] hello @me IYPBOTMessage added IYP.add_response [greeting_message] hey @sender IYPBOTResponse added IYPhello @IYPBOT IYPBOThey @IYP
Resources: A resource is an array of constant strings that can be used instead of a phrase or word in a message, a massage can contain several resource tags. You have to create a resource and then add the strings one by one to the resource.

Syntax to create a resource:.new_res
Syntax to add a resource.add_to_res string
Example:IYP.new_res IYPBOT Resource is added. IYP.add_to_res mat IYPBOTResource added.
Syntax for a resource tag:
Usage example:IYP.new_res IYPBOTResource is added. IYP.add_to_res mat IYPBOTResource added. IYP.add_message [do_i_know] do i know ? IYPBOTMessage added IYP.add_response [do_i_know] yes you do. IYPBOTResponse added IYPdo i know mat? IYPBOTyes you do. IYP.add_to_res iyp IYPBOTResource added. IYPdo i know iyp? IYPBOTyes you do.
What happens is that when the bot finds a resource tag in the message, it looks for the strings in the resource and checks to see if resource tag was replaced by any of these strings, would the message that users have sent fits into the category or not.

You can use the resource that was used in the message by user in the response. To do this you give an ID to each resource, and if the resource tag and ID that was used in message fits the resource tag and ID that is used in response, the user's value is used in the response.

Syntax for a resource tag with id:{resource_id}
Example:IYP.new_res IYPBOTResource is added. IYP.add_to_res mat IYPBOTResource added. IYP.add_message [do_i_know] do i know {0}? IYPBOTMessage added IYP.add_response [do_i_know] yes you do know {0} IYPBOTResponse added IYPdo i know mat? IYPBOTyes you do know mat
If a resource is used in a response but it isn't addressed by an ID (making it unable to use the resource used in message), the bot will use a random resource:

Example:IYP.new_res IYPBOTResource is added. IYP.add_to_res iyp IYPBOTResource added. IYP.add_to_res mat IYPBOTResource added. IYP.add_message [someone_i_know] get some one i know IYPBOTMessage added IYP.add_response [someone_i_know] IYPBOTResponse added IYPget some one i know IYPBOTmat IYPget some one i know IYPBOTiyp




<*> abstract resource: Every string fits in the abstract resource, it can be used with resource ID as well.

Example:IYP.add_message [repeat] repeat: <*>{0} and add this to end of it: <*>{1} IYPBOTMessage added IYP.add_response [repeat] <*>{0} , <*>{0}<*>{1} IYPBOTResponse added IYPrepeat: hello and add this to end of it: iyp IYPBOThello , helloiyp


NOTE: a message containing only <*> will block all the incoming messages



Porgrams:
You can add java programs and use them in the responses. Each program at least should have a public class, you can have several functions in classes, you will call the functions in responses, and the returned string will replace the program tag in response. For a function to be callable in responses, it should have the signiture below:public static String function_name(String[] argument_name)
class name and function name should be of lower case.

Syntax to add a program:.add_program ~file_name~ code

The file name should be the same as the name of the public class in the code.

Example: IYP.add_program ~memory~ public class memory { static String data=""; public static String save (String[] args) { data=args[0]; return "Data saved"; } public static String remember(String[] args) { return data; }} IYPBOTProgram added
To use a program you have to call it in a response, to do that you have to use program tag:

Syntax for program tag~file_name.class_name.function_name({ID}, {ID}, ...)~
you need at least a resource as argument to function

Example:IYP.add_program ~memory~ public class memory { static String data=""; public static String save (String[] args) { data=args[0]; return "Data saved"; } public static String remember(String[] args) { return data; }} IYPBOTProgram added IYP.add_message [save] save: <*>{0} IYPBOTMessage added IYP.add_response [save] ~memory.memory.save(<*>{0})~ IYPBOTResponse added IYP.add_message [read] read the data<*>{0} IYPBOTMessage added IYP.add_response [read] ~memory.memory.remember(<*>{0})~ IYPBOTResponse added IYPsave: hello IYPBOTData saved IYPread the data IYPBOThello
NOTE: every thing except program body is saved in lower case

To save your work use:
.save db database_name.db

To load use:
.load db database_name.db

You can merge several database with:
.add_db database_name.db
This will add a data base to the currently loaded database



For a quick help you can use ?help

If you wanted to use the bot PM me on the chat so i add you to white list to allow access to commands
If you had any problem understanding any part of this please let me know thanks :D , i'd be glad if anyone wanted to try the bot :D

Source code on github:
https://github.com/iyp-programer-yeah/iyp_bot

Previous Entry WoA Day 7
Next Entry WoA V Day 1
1 likes 2 comments

Comments

Navyman

Why did someone down vote this?

August 21, 2016 07:14 AM
IYP

newtechnology did, coz of personal problems lol :D

August 21, 2016 09:37 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

IYP Bot 2.0

2198 views

WoA V Day 7

1947 views

WoA V Day 6

2543 views

WoA V Day V

2349 views

WoA V Day 4

2211 views

WoA V Day 3

1994 views

WoA V Day 2

2207 views

WoA V Day 1

3382 views
Advertisement