Thread: [Plugin] ChatBridge (Multipurpose bi-directional chat relaying eg. for Discord/IRC)

Results 1 to 4 of 4
  1. #1
    incognico nico's Avatar
    Join Date
    Aug 2015
    Posts
    449

    [Plugin] ChatBridge (Multipurpose bi-directional chat relaying eg. for Discord/IRC)

    This is a multipurpose bi-directional chat relaying script working via simple text files in scripts/plugins/store/.

    ChatBridge.as is the Sven Co-op AngelScript part. To actually do cool stuff with this script you need an external application writing to the infile and reading from the outfile.

    Configuration is done in the header of the Script. The options are commented and/or self-explainable.
    The in and outfiles must exist before running the script as there is no checking for that.

    Quick run down on how it works and how it should be used:

    • Any player chat will be printed to g_FromSven using a format of
      • <nickname><STEAM_0:I:D> whole chat line
    • If joinsquits is true the format for joins and quits respectively is
      • + <nickname><STEAM_0:I:D> has joined the game
      • - <nickname><STEAM_0:I:D> has left the game
    • On map start g_FromSven is truncated
    • Any line in g_ToSven will be printed as-is to the chat area (HUD_PRINTTEXT), so do the nessecary formatting the the external application
    • Every delay g_FromSven is flushed and g_ToSven will be read and truncated if there was input
    • After every map change + statusdelay the current map and the current player count is written to g_FromSven too in the following format (example with 12 players)
      • status mapname 12


    Download: scripts/plugins/ChatBridge.as

    Note:
    You might want to place this as the very last script in default_plugins.txt to prevent SayText which was already handled by other plugins to end up in there.


    Example of how it can be used (External App being a Perl Discord bot tailing g_FromSven and writing to g_ToSven):

    Line "status arcad2_v 9" sets the status and announces the map, the other lines are normal chat.

    Click image for larger version. 

Name:	1gus.png 
Views:	138 
Size:	79.1 KB 
ID:	17912

    Click image for larger version. 

Name:	a.png 
Views:	185 
Size:	65.5 KB 
ID:	17922

    And writing on Discord results in:

    Click image for larger version. 

Name:	2.png 
Views:	111 
Size:	72.7 KB 
ID:	17914


    You can write your own bot or:


    Bonus (DiscordStatus):
    No support for stuff in this section I consider it abandoned.

    If you just want to have the status lines (map name and player count) relayed to Discord, without a real Discord bot you can use the script DiscordStatus.as - it's the one ChatBridge.as evolved from.

    It utilizes Discord WebHooks and is written in Perl too. It was desigend to have one dedicated channel where every map will be announced and one channel where only map series are announced in a fancier way.
    It's small and can be edited easily, just remove the custom emoji stuff (<:hl:369091257999294464>) those are specific to the twlz Discord server and then create the webhooks and set the two url variables.

    Looks like this:

    for $webhookurl_serverstatus
    Click image for larger version. 

Name:	3.png 
Views:	113 
Size:	23.1 KB 
ID:	17915

    for $webhookurl_general
    Click image for larger version. 

Name:	4.png 
Views:	79 
Size:	32.1 KB 
ID:	17916

    Download:
    scripts/plugins/DiscordStatus.as
    misc/scdiscordbridge.pl
    (Requires File::Tail + LWP::UserAgent)

    PS: This thread is for ChatBridge.as and I won't help you developing external applications for it, thats up to you.
    Last edited by nico; 28-12-2017 at 01:16 PM.

  2. #2
    QPU-aligned Silencer's Avatar  
    Contributor
    Join Date
    May 2006
    Posts
    6,082

    Re: [Plugin] ChatBridge (Multipurpose bi-directional chat relaying eg. for Discord/IR

    I already wondered when someone would realize they could use a text file to communicate with virtually any API. Very cool application!

  3. #3
    Registered User
    Join Date
    Apr 2016
    Posts
    77

    Re: [Plugin] ChatBridge (Multipurpose bi-directional chat relaying eg. for Discord/IR

    How to install this plugin?

  4. #4
    Server Manager
    Join Date
    Oct 2019
    Location
    Finland
    Posts
    4

    Re: [Plugin] ChatBridge (Multipurpose bi-directional chat relaying eg. for Discord/IR

    Do i paste the code from scdiscordbridge.pl, does the bot automatically run if i do that and how do i keep it online 24/7 without having my computer on?
    I could also host the bot directly from my phone if there is an application to run the code on phone.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •