-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
1,228 additions
and
729 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
namespace Ctor.Xmpp | ||
|
||
open System | ||
open System.Threading | ||
|
||
open Microsoft.Extensions.Logging | ||
open SharpXMPP | ||
open SharpXMPP.XMPP | ||
|
||
type Robot(loggerFactory: ILoggerFactory, | ||
login: string, | ||
password: string, | ||
roomJid: string, | ||
nickname: string) = | ||
let logger = loggerFactory.CreateLogger<Robot>() | ||
let connection = new XmppClient(JID(login), password) | ||
|
||
let connectionFailedHandler = XmppConnection.ConnectionFailedHandler(fun s e -> | ||
logger.LogError(e.ToString()) | ||
Thread.Sleep(TimeSpan.FromSeconds(30.0)) // TODO[Friedrich]: Configurable timeout. | ||
()) | ||
|
||
let signedInHandler = XmppConnection.SignedInHandler(fun s e -> | ||
logger.LogInformation("Connecting to " + roomJid) | ||
SharpXmppHelper.joinRoom connection roomJid nickname) | ||
|
||
let messageHandler = XmppConnection.MessageHandler(fun s e -> | ||
logger.LogInformation("<-" + e.ToString())) | ||
|
||
let elementHandler = XmppConnection.ElementHandler(fun s e -> | ||
let arrow = if e.IsInput then "<-" else "->" | ||
logger.LogInformation(arrow + " " + e.ToString())) | ||
|
||
do | ||
connection.add_ConnectionFailed(connectionFailedHandler) | ||
connection.add_SignedIn(signedInHandler) | ||
connection.add_Message(messageHandler) | ||
connection.add_Element(elementHandler) | ||
|
||
interface IDisposable with | ||
member __.Dispose() = connection.Close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Ctor.Xmpp.SharpXmppHelper | ||
|
||
open System.Xml.Linq | ||
|
||
open SharpXMPP | ||
open SharpXMPP.XMPP.Client.MUC.Bookmarks.Elements | ||
|
||
let private bookmark (roomJid: string) (nickname: string): BookmarkedConference = | ||
let room = BookmarkedConference() | ||
room.SetAttributeValue(XName.Get("jid"), roomJid) | ||
let nickElement = XElement(XName.Get("storage:bookmarks"), "nick", Value = nickname) | ||
room.Add(nickElement) | ||
room | ||
|
||
let joinRoom (client: XmppClient) (roomJid: string) (nickname: string): unit = | ||
let room = bookmark roomJid nickname | ||
client.BookmarkManager.Join(room) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.