class Database
include Cinch::Plugin
DB = SQLite3::Database.new('development.sqlite3')
match /(select .* from gears where .* like .*)/i
def execute(m)
@db = SQLite3::Database.new('development.sqlite3')
#m.reply @db.execute("select * from gears where lab like 'Primary'")
end
end
IRC机器人的这一部分。我正在尝试将用户输入直接输入到 @db.execute的匹配的正则拨正等级以执行查询。对于有其他方式的任何帮助或建议将不胜感激。
沿着这些行的某些东西应该有效:
def execute(m)
@db = SQLite3::Database.new('development.sqlite3')
input = m.input # or however you're getting the input into this function
regex = /(select .* from gears where .* like .*)/i
db_query_string = regex.match(input).to_s
m.reply @db.execute(db_query_string)
end