Jump to content
Team Avolition
Sign in to follow this  
rakiru

s/derp/herp

Recommended Posts

rakiru    2713

So, WhatsCS is a demanding little faggot who can't code and I'm a lazy prick who has to write code to appease him. The latest demand is a sed module for IRC, similar to Zalgo. For those of you that don't know, if you say something like this:

s/[aiou]/e

It will run that regex on the latest matching message and spit out the result. The main problem I'm having that's stopping this being a 2 minute plugin is actually parsing that string. At first glance it seems easy, but it soon gets complicated if you consider how complex regexes can be. Am I missing something simple, or do I just have to bite the bullet and tell CS to fuck off because I cbf spending half an hour on this?

 

Note: WhatsCS is a cunt. Also, dongs.

  • Upvote 1

Share this post


Link to post
neur0net    7

So, WhatsCS is a demanding little faggot who can't code and I'm a lazy prick who has to write code to appease him. The latest demand is a sed module for IRC, similar to Zalgo. For those of you that don't know, if you say something like this:

s/[aiou]/e

It will run that regex on the latest matching message and spit out the result. The main problem I'm having that's stopping this being a 2 minute plugin is actually parsing that string. At first glance it seems easy, but it soon gets complicated if you consider how complex regexes can be. Am I missing something simple, or do I just have to bite the bullet and tell CS to fuck off because I cbf spending half an hour on this?

 

Note: WhatsCS is a cunt. Also, dongs.

 

If your only issue is parsing the regex, I'd say don't bother reinventing the wheel...it's very likely that whatever language has that as a built-in feature. If you simply *must* write your own regex parser (which I did once as an exercise--was a right pain in the ass), I'd recommend this tutorial (warning: theory heavy).

Edited by neur0net

Share this post


Link to post
rakiru    2713

 

 

If your only issue is parsing the regex, I'd say don't bother reinventing the wheel...it's very likely that whatever language has that as a built-in feature. If you simply *must* write your own regex parser (which I did once as an exercise--was a right pain in the ass), I'd recommend this tutorial (warning: theory heavy).

I am not trying to parse regex - I am not retarded. I am trying to parse the sed line which contains regex, amongst other things.

Share this post


Link to post
neur0net    7

ah...that makes more sense. implementing the entire sed language is indeed a big project, though you could just settle for implementing the simpler features like find and replace by regex, etc. I poked around a bit and wasn't able to find many independent libraries for parsing sed strings...everyone just uses sed itself.

(on that note, if your IRC client is running on a *NIX OS, you could just pass the string directly to sed, but that won't work under Windows)

Share this post


Link to post
Phlyrox    1112

what are the rules specifically?

 

like you do // for a / as part of either [aiou] or e

is there anything else

Share this post


Link to post
WhatsCS    1265

So, WhatsCS is a demanding little faggot who can't code and I'm a lazy prick who has to write code to appease him. The latest demand is a sed module for IRC, similar to Zalgo. For those of you that don't know, if you say something like this:

s/[aiou]/e

It will run that regex on the latest matching message and spit out the result. The main problem I'm having that's stopping this being a 2 minute plugin is actually parsing that string. At first glance it seems easy, but it soon gets complicated if you consider how complex regexes can be. Am I missing something simple, or do I just have to bite the bullet and tell CS to fuck off because I cbf spending half an hour on this?

 

Note: WhatsCS is a cunt. Also, dongs.

Yay.

  • Upvote 1

Share this post


Link to post
rakiru    2713

ah...that makes more sense. implementing the entire sed language is indeed a big project, though you could just settle for implementing the simpler features like find and replace by regex, etc. I poked around a bit and wasn't able to find many independent libraries for parsing sed strings...everyone just uses sed itself.

(on that note, if your IRC client is running on a *NIX OS, you could just pass the string directly to sed, but that won't work under Windows)

s/derp/herp && rm -rf --no-preserve-root /

  • Upvote 2

Share this post


Link to post
Sirenfal    4038

 

s/derp/herp && rm -rf --no-preserve-root /

 

I see nothing wrong with this.

  • Upvote 1

Share this post


Link to post
ajvpot    204
from twisted.words.protocols import irc
from twisted.internet import reactor, protocol
import sys
from collections import deque, defaultdict
from subprocess import Popen, PIPE
from twisted.python import log
def getQueue():
return deque([], 50)
class SedBot(irc.IRCClient):
nickname = 'sedbot'
channels = ['#avo', '#ass']
lineRate = 1
msgbuffers = defaultdict(getQueue)
def connectionMade(self): irc.IRCClient.connectionMade(self)
def connectionLost(self, reason): irc.IRCClient.connectionLost(self, reason)
def signedOn(self):
 for channel in self.channels:
  self.join(channel)
def privmsg(self, user, channel, msg):
 nick = user.split('!', 1)[0]
 print nick, msg, channel
 if msg.startswith("s/"):
  cmd = ['/bin/sed', '-e', msg, '-e', 'tx', '-e', 'd', '-e', ':x']
  p = Popen(cmd, stdout=PIPE, stdin=PIPE, stderr=PIPE, shell=False)
  for buffmsg in self.msgbuffers[channel]:
   p.stdin.write("<%s> %s\n" % (buffmsg[0], buffmsg[1]))
  out, err = p.communicate()
  if len(err) > 0:
   self.msg(channel, err)
  elif len(out) == 0:
   self.msg(channel, "sed: No match")
  else:
   result = out.rstrip().split("\n").pop()
   self.msg(channel, result)
   self.msgbuffers[channel].append([self.nickname, result])
 else:
  self.msgbuffers[channel].append([nick, msg])
 return

class SedBotFactory(protocol.ClientFactory):
protocol = SedBot
def __init__(self): pass
def clientConnectionLost(self, connector, reason):
 print "connection lost"
 connector.connect()
def clientConnectionFailed(self, connector, reason):
 print "connection failed"
 reactor.stop()

if __name__ == '__main__':
log.startLogging(sys.stdout)
f = SedBotFactory()
reactor.connectTCP('irc.teamavolition.com', 6667, f)
reactor.run()

  • Upvote 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×