1
0
Fork 0
mirror of https://github.com/nishiki/botish.git synced 2024-11-23 08:07:52 +00:00

first commit

This commit is contained in:
Adrien Waksberg 2017-04-17 11:07:45 +02:00
commit 7d31b828fb
3 changed files with 181 additions and 0 deletions

122
.rubocop.yml Normal file
View file

@ -0,0 +1,122 @@
AllCops:
Exclude:
- db/**/*
- config/**/*
- test/*
- Vagrantfile
TargetRubyVersion: 2.3
Style/AccessorMethodName:
Enabled: false
Style/NumericLiteralPrefix:
Enabled: false
Style/TrailingCommaInArguments:
Enabled: false
Style/TrailingCommaInLiteral:
Enabled: false
Style/FrozenStringLiteralComment:
Enabled: false
Metrics/ParameterLists:
Max: 5
CountKeywordArgs: false
Style/MutableConstant:
Enabled: false
Metrics/LineLength:
Max: 120
Metrics/AbcSize:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
Metrics/ClassLength:
Enabled: false
Style/SpaceInsideHashLiteralBraces:
Enabled: false
Style/AsciiComments:
Enabled: true
Style/Documentation:
Enabled: false
Style/SignalException:
Enabled: false
Style/OptionHash:
Enabled: true
Style/SymbolArray:
Enabled: true
Performance/Casecmp:
Enabled: false
Style/DoubleNegation:
Enabled: false
Style/Alias:
EnforcedStyle: prefer_alias_method
Style/MultilineMethodCallIndentation:
EnforcedStyle: indented
Style/RaiseArgs:
EnforcedStyle: exploded
Style/SpaceInLambdaLiteral:
Enabled: false
Lint/UnneededSplatExpansion:
Enabled: false
# Generated configuration
Style/HashSyntax:
Enabled: true
EnforcedStyle: ruby19
UseHashRocketsWithSymbolValues: false
Style/MethodDefParentheses:
Enabled: true
EnforcedStyle: require_parentheses
Style/MultilineAssignmentLayout:
Enabled: true
EnforcedStyle: new_line
Style/IndentationConsistency:
Enabled: true
EnforcedStyle: normal
Style/AlignParameters:
Enabled: true
EnforcedStyle: with_fixed_indentation
Style/BlockDelimiters:
Enabled: true
EnforcedStyle: line_count_based
Style/AndOr:
Enabled: true
Style/DotPosition:
Enabled: true
EnforcedStyle: leading
Style/EmptyLinesAroundClassBody:
Enabled: true
EnforcedStyle: no_empty_lines
Style/EmptyLinesAroundModuleBody:
Enabled: true
EnforcedStyle: no_empty_lines
Style/NumericPredicate:
Enabled: true
EnforcedStyle: comparison
Style/EvenOdd:
Enabled: false
Style/CollectionMethods:
Enabled: true
PreferredMethods:
collect: map
collect!: map!
inject: reduce
detect: find
find_all: select
Style/EmptyLinesAroundAccessModifier:
Enabled: true
Style/CommandLiteral:
Enabled: true
EnforcedStyle: percent_x
Style/StringLiterals:
Enabled: true
EnforcedStyle: single_quotes
Style/SpaceInsideBlockBraces:
EnforcedStyle: space
Style/VariableNumber:
EnforcedStyle: snake_case

7
bin/botish Executable file
View file

@ -0,0 +1,7 @@
#!/usr/bin/ruby
$LOAD_PATH << File.expand_path('../../lib', __FILE__)
require 'botish'
Botish.new.listen

52
lib/botish.rb Normal file
View file

@ -0,0 +1,52 @@
#!/usr/bin/ruby
require 'socket'
class Botish
HOST = 'irc.freenode.net'
PORT = 6667
USERNAME = 'botish'
CHANNEL = '#testnishiki'
def initialize
@connection = TCPSocket.open(HOST, PORT)
send("NICK #{USERNAME}")
send("USER #{USERNAME} localhost * :#{USERNAME}")
Kernel.loop do
msg = @connection.gets
log("<- #{msg}")
break if msg.include?('End of /MOTD command.')
end
send("JOIN #{CHANNEL}")
send("PRIVMSG #{CHANNEL} :Je suis là :')")
end
def listen
Kernel.loop do
msg = @connection.gets
log("<- #{msg}")
parse(msg)
end
end
private
def parse(msg)
case msg
when /^PING (?<host>.+)/
send("PONG #{Regexp.last_match('host')}")
when /^:(?<user>[[:alpha:]]+)([^ ]+)? PRIVMSG #{CHANNEL} :#{USERNAME}: ping/
send("PRIVMSG #{CHANNEL} :#{Regexp.last_match('user')}: pong")
end
end
def send(msg)
log("-> #{msg}")
@connection.puts(msg)
end
def log(msg)
puts "#{Time.now.strftime('%Y-%m-%d %H:%M:%S.%L')} #{msg}"
end
end