Coder Social home page Coder Social logo

simpleirc's Introduction

SimpleIRC

SimpleIRC is a simple IRC Library for haskell.

Installation

To install SimpleIRC as a library you need cabal.

You can then use cabal install to install.

Example

For an example on how to use the library see example/example.hs and tests/testbot.hs

I'm also creating an IRC Bot which uses this library. Take a look at it for more practical usage of the lib.

Usage

The first step is to create an IrcConfig datatype. You have to specify the address of the server, the server port, nickname, username, realname, list of channels to join when connected, and a list of events which will be called when certain commands are received from the server.

You can specify 0 events, if for some unlikely reason you want your bot to not respond to anything. But in the more likely event when you do want to specify functions, you can do that simply by creating a function with the type of EventFunc

onMessage :: EventFunc

EventFunc has the type of (IrcServer -> IrcMessage -> IO ()). For Haskell beginners that's a function which takes two arguments; an IrcServer and an IrcMessage, and which returns a IO ()

onMessage server msg
  | m == "|hello" = do
    sendMsg server chan "hello!"
  | otherwise = return ()
  where chan = fromJust $ mChan m
        m    = mMsg msg

This function will send "hello" to a channel whenever someone says "|hello".

Then you can pass [(Privmsg onMessage)] to IrcConfig.

Take a look at the IrcEvent type in Network/SimpleIRC/Core.hs to see other events.

There is one(as of now) event which doesn't take a EventFunc function. You should be able to figure out what type of function it does take by looking at Network/SimpleIRC/Core.hs

After you create a IrcConfig you can then call connect. Connect takes two arguments; the IrcConfig and a boolean. The boolean specifies whether to run the listenLoop in a new thread.

If you have any questions you can ask them @ irc://irc.freenode.net/#()

License

SimpleIRC is licensed under the BSD3 license. Read the license file for more information.

simpleirc's People

Contributors

dom96 avatar edwtjo avatar fuuzetsu avatar lcycon avatar mklinik avatar mstksg avatar norriscm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

simpleirc's Issues

Lenses?

I just released simpleirc-lens. But it's simple enough that I wonder if you just want to merge it into this project. It doesn't depend on lens, the lenses are done manually (as opposed to using the pretty TemplateHaskell generator in lens), so there would be no new deps.

If there's no interest, feel free to close this, but if there is, I can send a PR.

RawMessage event

This may help with implementing features such as a lag meter for a user using this lib.

Callback on timer

Hi,

Besides binding a function on Ping, is there a way to have some arbitrary function be called once in a while ? I need to check on an external API for notifications (to send them on the irc channel), and I don't want to put that in PrivMsg since that would require people to be active for it to work.
I don't see a way to get the parameters for sendMsg outside of a callbacks, so a timer would be great.

connect should return something other than an IrcServer

When connect starts a new thread, the IrcServer it returns is not the same as the one inside the listener thread, which is inaccessible. When connect /doesn't/ start a new thread, the IrcServer it returns is invalid by the time the function returns.

Upload to Hackage

Any plans to upload a new version to Hackage? The version on Hackage is currently unbuildable with GHC-7.10. This issue was fixed by commit 577a9ab, but never reached Hackage.

Thanks!

Uploading to stackage?

Hi! Thanks for the great package, it's been very useful to me! :D i've been using it for a while now for my own projects :)

Just wondering if there any plans to put simpleirc onto the stackage package database?

(If you wanted to, it's as simple as editing this file)

On freenode, action is incorrect

When I tried using action, this happened

[Sunday, August 30, 2015] [8:16:52 PM EDT] <agjksdagdsfgjk> ¬TION X(�
[Sunday, August 30, 2015] [8:17:04 PM EDT] <agjksdagdsfgjk> ¬TION Why am I failing?�

Warning: Fields of `IrcConfig' not initialised: cAddr, cNick

Hi,

When installing SimpleIRC I get a warning. Don't know if it's of any importance but thought I'd share it here. I'm using Haskell Platform 2011.2

C:\Users\Christiaan>cabal install simpleirc
Resolving dependencies...
Downloading simpleirc-0.2.0...
Configuring simpleirc-0.2.0...
Preprocessing library simpleirc-0.2.0...
Building simpleirc-0.2.0...
[1 of 3] Compiling Network.SimpleIRC.Messages ( Network\SimpleIRC\Messages.hs, d
ist\build\Network\SimpleIRC\Messages.o )
[2 of 3] Compiling Network.SimpleIRC.Core ( Network\SimpleIRC\Core.hs, dist\buil
d\Network\SimpleIRC\Core.o )

Network\SimpleIRC\Core.hs:467:17:
    Warning: Fields of `IrcConfig' not initialised: cAddr, cNick
    In the expression:
      IrcConfig
        {cPort = 6667, cUsername = "simpleirc",
         cRealname = "SimpleIRC Bot", cChannels = [], cEvents = [],
         cCTCPVersion = "SimpleIRC v0.2",
         cCTCPTime = fmap (formatTime defaultTimeLocale "%c") getZonedTime}
    In an equation for `defaultConfig':
        defaultConfig
          = IrcConfig
              {cPort = 6667, cUsername = "simpleirc",
               cRealname = "SimpleIRC Bot", cChannels = [], cEvents = [],
               cCTCPVersion = "SimpleIRC v0.2",
               cCTCPTime = fmap (formatTime defaultTimeLocale "%c") getZonedTime
}
[3 of 3] Compiling Network.SimpleIRC ( Network\SimpleIRC.hs, dist\build\Network\
SimpleIRC.o )
Registering simpleirc-0.2.0...
Installing library in
C:\Users\Christiaan\AppData\Roaming\cabal\simpleirc-0.2.0\ghc-7.0.2
Registering simpleirc-0.2.0...

SSL Support

This could be a low priority feature but it would be nice for some people.

Race condition in disconnect

When you call disconnect, there is a possibility that the listen loop thread is in the middle of checking messages. This causes the following error:

>> :[email protected] QUIT :Client Quit
>> ERROR :Closing Link: ....lightspeed.cicril.sbcglobal.net (Client Quit)

I can't find where it is specified in the RFC for the IRC protocol, but it seems that after issuing a QUIT message to the server, the server will broadcast QUIT to every channel you're in before actually closing the connection. (At least, this is how it works on Freenode).

Perhaps there should be a test in the listen loop to terminate, not just on EOF, but also when a QUIT message is received after a call to disconnect.

If this sound agreeable, I'll happily throw together a patch.

readme.markdown typo

I dind't tested it but i think it should be a "server" instead of "s" in

onMessage server msg
| m == "|hello" = do
sendMsg s chan "hello!"
| otherwise = return ()
where chan = fromJust $ mChan m
m = mMsg msg

test-suite build failure

$ cabal install --enable-tests simpleirc-0.3.1/
Resolving dependencies...
Notice: installing into a sandbox located at
/Users/adam/repos/trustee/simpleirc/.cabal-sandbox
Configuring HUnit-1.3.1.1...
Configuring ansi-terminal-0.6.2.3...
Configuring base64-bytestring-1.0.0.1...
Configuring byteable-0.1.1...
Downloading hourglass-0.2.10...
Building base64-bytestring-1.0.0.1...
Building ansi-terminal-0.6.2.3...
Building HUnit-1.3.1.1...
Building byteable-0.1.1...
Installed byteable-0.1.1
Configuring cereal-0.5.1.0...
Building cereal-0.5.1.0...
Configuring data-default-class-0.0.1...
Installed base64-bytestring-1.0.0.1
Building data-default-class-0.0.1...
Configuring hspec-discover-2.2.3...
Installed data-default-class-0.0.1
Configuring knob-0.1.1...
Installed HUnit-1.3.1.1
Building hspec-discover-2.2.3...
Building knob-0.1.1...
Configuring memory-0.11...
Installed ansi-terminal-0.6.2.3
Building memory-0.11...
Configuring mtl-2.2.1...
Installed knob-0.1.1
Configuring network-2.6.2.1...
Installed hspec-discover-2.2.3
Building mtl-2.2.1...
Configuring old-locale-1.0.0.7...
Installed mtl-2.2.1
Building network-2.6.2.1...
Building old-locale-1.0.0.7...
Configuring primitive-0.6.1.0...
Installed old-locale-1.0.0.7
Building primitive-0.6.1.0...
Configuring setenv-0.1.1.3...
Installed memory-0.11
Downloading cryptonite-0.13...
Building setenv-0.1.1.3...
Configuring random-1.1...
Installed setenv-0.1.1.3
Configuring stm-2.4.4.1...
Installed cereal-0.5.1.0
Building random-1.1...
Building stm-2.4.4.1...
Configuring hourglass-0.2.10...
Installed primitive-0.6.1.0
Building hourglass-0.2.10...
Installed stm-2.4.4.1
Configuring hspec-expectations-0.7.2...
Building hspec-expectations-0.7.2...
Configuring pem-0.2.2...
Installed hspec-expectations-0.7.2
Building pem-0.2.2...
Configuring cryptonite-0.13...
Installed pem-0.2.2
Configuring async-2.1.0...
Installed random-1.1
Configuring tf-random-0.5...
Installed network-2.6.2.1
Building cryptonite-0.13...
Building async-2.1.0...
Building tf-random-0.5...
Configuring socks-0.5.4...
Installed async-2.1.0
Building socks-0.5.4...
Installed tf-random-0.5
Configuring QuickCheck-2.8.2...
Building QuickCheck-2.8.2...
Installed hourglass-0.2.10
Configuring asn1-types-0.3.2...
Installed socks-0.5.4
Building asn1-types-0.3.2...
Installed asn1-types-0.3.2
Configuring asn1-encoding-0.9.3...
Building asn1-encoding-0.9.3...
Installed asn1-encoding-0.9.3
Configuring asn1-parse-0.9.4...
Building asn1-parse-0.9.4...
Installed asn1-parse-0.9.4
Installed QuickCheck-2.8.2
Configuring quickcheck-io-0.1.2...
Building quickcheck-io-0.1.2...
Installed quickcheck-io-0.1.2
Downloading hspec-core-2.2.3...
Configuring hspec-core-2.2.3...
Building hspec-core-2.2.3...
Installed hspec-core-2.2.3
Downloading hspec-2.2.3...
Configuring hspec-2.2.3...
Building hspec-2.2.3...
Installed hspec-2.2.3
Installed cryptonite-0.13
Configuring x509-1.6.3...
Building x509-1.6.3...
Installed x509-1.6.3
Configuring x509-store-1.6.1...
Building x509-store-1.6.1...
Installed x509-store-1.6.1
Configuring x509-system-1.6.3...
Configuring x509-validation-1.6.3...
Building x509-system-1.6.3...
Building x509-validation-1.6.3...
Installed x509-system-1.6.3
Installed x509-validation-1.6.3
Configuring tls-1.3.4...
Building tls-1.3.4...
Installed tls-1.3.4
Configuring connection-0.2.5...
Building connection-0.2.5...
Installed connection-0.2.5
Configuring simpleirc-0.3.1...
Building simpleirc-0.3.1...
Failed to install simpleirc-0.3.1
Build log ( /Users/adam/repos/trustee/simpleirc/.cabal-sandbox/logs/simpleirc-0.3.1.log ):
cabal: Entering directory 'simpleirc-0.3.1/'
Configuring simpleirc-0.3.1...
Building simpleirc-0.3.1...
Preprocessing library simpleirc-0.3.1...
[1 of 3] Compiling Network.SimpleIRC.Messages ( Network/SimpleIRC/Messages.hs, dist/dist-sandbox-6e07f38a/build/Network/SimpleIRC/Messages.o )
[2 of 3] Compiling Network.SimpleIRC.Core ( Network/SimpleIRC/Core.hs, dist/dist-sandbox-6e07f38a/build/Network/SimpleIRC/Core.o )
[3 of 3] Compiling Network.SimpleIRC ( Network/SimpleIRC.hs, dist/dist-sandbox-6e07f38a/build/Network/SimpleIRC.o )
Preprocessing test suite 'spec' for simpleirc-0.3.1...

tests/Spec.hs:3:18:
    Could not find module ‘Test.Hspec.Monadic’
    Perhaps you meant
      Test.Hspec.Config
      Test.Hspec.HUnit (from hspec-2.2.3@CCgMvvfb19d8Mrl0Hh3HVR)
    Use -v to see a list of the files searched for.

tests/Spec.hs:4:18:
    Could not find module ‘CoreSpec’
    Use -v to see a list of the files searched for.
cabal: Leaving directory 'simpleirc-0.3.1/'
cabal: Error: some packages failed to install:
simpleirc-0.3.1 failed during the building phase. The exception was:
ExitFailure 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.