Created
May 29, 2015 03:36
-
-
Save anonymous/7bd86cb6c731e29bd45a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sqlite3' | |
class Alias | |
include Cinch::Plugin | |
match(/alias\screate\s(.+?)\s(.+)/, method: :create_alias) | |
match(/alias\sshow\s(.+)/, method: :show_alias) | |
def initialize(*args) | |
super | |
@db = SQLite3::Database.open "aliases.db" | |
end | |
#def execute(m, name, desc) | |
# m.reply(create_alias(name, desc)) | |
#end | |
def create_alias(m, name, desc) | |
begin | |
@db.execute("create table if not exists aliases(id integer primary key autoincrement, | |
name text, desc text)") | |
@db.execute("insert into aliases (name, desc) values (?, ?)", [name, desc]) | |
m.reply("«output» alias added successfully") | |
rescue SQLite3::Exception | |
m.reply("«output» alias could not be added") | |
end | |
end | |
def show_alias(m, name) | |
begin | |
@db.execute("select name,desc from aliases") do |r| | |
m.reply("«output» #{r[1]}") if name == r.first | |
end | |
rescue SQLite3::Exception | |
end | |
end | |
private :create_alias | |
private :show_alias | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment